Requires
EntityFramework.dll.
When creating an Entity Framework model, several options are available:
- Code First: Define the model using code, then generate the database from this.
- Code First to Existing Database: Use code to create the model that maps to an existing database.
- Model First: Define the model in a graphical editor and generate a database from this.
- Database First: Create a model in the graphical editor that maps to an existing database.
DbModelBuilder
Exists within the
System.Data.Entity namespace,
DbModelBuilder maps classes to a database schema. It could be used for the 'code first' method, or generated by building a 'database first' Entity Framework model. Here the model can be configured by overriding the DbContext.
The
DbModelBuilder class contains:
- public DbModelBuilder()
- public DbModelBuilder(DbModelBuilderVersion modelBuilderVersion)
- public virtual ConfigurationRegistrar Configurations { get; }
- public virtual DbModel Build(DbConnection providerConnection)
- public virtual DbModel Build(DbProviderInfo providerInfo)
- public virtual ComplexTypeConfiguration ComplexType() where TComplexType : class;
- public virtual EntityTypeConfiguration Entity() where TEntityType : class;
public override bool Equals(object obj)
- public override int GetHashCode()
- public Type GetType()
- public virtual DbModelBuilder HasDefaultSchema(string schema)
Sending Data to Stored Procedures
The following code is found in
[DatabaseName].Context.cs:
public virtual ObjectResult prStoredProcedure(Nullable noOfDays)
{
var noOfDaysParameter = noOfDays.HasValue ?
new ObjectParameter("NoOfDays", noOfDays) :
new ObjectParameter("NoOfDays", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("prStoredProcedure", noOfDaysParameter);
}
References
ENTITYFRAMEWORKTUTORIAL.NET. 2016.
Entity Framework Tutorial. [WWW].
www.entityframeworktutorial.net. 21st April 2017.