Entity Framework - xerocrypt/Misc GitHub Wiki

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.

Sending Data to Stored Procedures The following code is found in [DatabaseName].Context.cs:

public virtual ObjectResult<prStoredProcedure_Result> prStoredProcedure(Nullable<int> noOfDays)

{

`var noOfDaysParameter = noOfDays.HasValue ?`

`new ObjectParameter("NoOfDays", noOfDays) :`

`new ObjectParameter("NoOfDays", typeof(int));`

`return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<prStoredProcedure_Result>("prStoredProcedure", noOfDaysParameter);`

}

Return Data

public partial class prStoredProcedure_Result

{

`public Nullable<System.Guid> Id { get; set; }`

`public string HealthBoard { get; set; }`

`public string HealthBoardDescription { get; set; }`

`public Nullable<int> MessagesProcessed { get; set; }`

}

References

ENTITYFRAMEWORKTUTORIAL.NET. 2016. Entity Framework Tutorial. [WWW]. http://www.entityframeworktutorial.net. 21st April 2017.

⚠️ **GitHub.com Fallback** ⚠️