Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

EntityFramework.OracleHelpers

Collection of Entity Framework Conventions implementing Oracle uppercase naming conventions.

OracleHelpers comes with uppercase naming conventions for columns, tables and foreign keys. Also there is convention for properties of type string.

Installation

Install via NuGet:

PM> Install-Package EntityFramework.OracleHelpers

Usage

Add using to your DbContext class and apply conventions:

usingEntityFramework.OracleHelpers;protectedoverridevoidOnModelCreating(DbModelBuildermodelBuilder){this.ApplyAllConventionsIfOracle(modelBuilder);}

That's it. One line and all default conventions will be applied if your connectionstring point to Oracle database.

Conventions

OracleHelpers comes with following conventions:

  • UpperCaseColumnNameConvention
  • UpperCaseTableNameConvention
  • UpperCaseForeignKeyNameConvention
  • StringPropertyMaxLengthConvention

All UpperCase*NameConvention convert all names from default C# PascalCase to Oracle UpperCase. Basically from your class:

publicclassProduct{publicintId{get;set;}publicstringProductName{get;set;}publicDateTimeOnSaleFrom{get;set;}}

You will get table:

PRODUCTS
ID
PRODUCT_NAME
ON_SALE_FROM

Note:

All UpperCase*NameConvention defaults to uppercase with underscore separated words but that can be overriden by constructor parameter.

StringPropertyMaxLengthConvention

As per Oracle documentation .NET Data Type String will be represented as Oracle NCLOB if MaxLength attribute is not set. StringPropertyMaxLengthConvention sets MaxLength to 2000 for all strings so you'll get NVARCHAR2(2000) column for your strings.

If needed you can override length per case if needed. So:

publicclassUser{publicintId{get;set;}publicstringFirstName{get;set;}[StringLength(100)]publicstringMiddleName{get;set;}[StringLength(7000)]publicstringLastName{get;set;}}

Should look like this:

USERSTYPE
ID
FIRST_NAMENVARCHAR2(2000)
MIDDLE_NAMENVARCHAR2(100)
LAST_NAMENCLOB

Examples

Apply all conventions with default values if ProviderInvariantName for current connection is Oracle.ManagedDataAccess.Client otherwise does nothing:

protectedoverridevoidOnModelCreating(DbModelBuildermodelBuilder){this.ApplyAllConventionsIfOracle(modelBuilder);base.OnModelCreating(modelBuilder);}

You can check by yourself if on Oracle and apply some of conventions or change defaults:

protectedoverridevoidOnModelCreating(DbModelBuildermodelBuilder){if(this.IsOracle()){modelBuilder.ApplyAllUpperCaseConventions(convertToUnderscore:false);modelBuilder.ApplyStringMaxLengthConvention();}base.OnModelCreating(modelBuilder);}

Ofcourse, you could apply those conventions even if you are not on Oracle database.

About

Collection of Entity Framework Conventions implementing Oracle naming conventions

Resources

Stars

8 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages