Generic Repository EF6 (edit)
EF: http://www.entityframeworktutorial.net/
EF Core: https://www.learnentityframeworkcore.com/
Design Patterns: Generic Repository, Unit of Work,
How to: Use EdmGen.exe to Generate the Model and Mapping Files
https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ef/how-to-use-edmgen-exe-to-generate-the-model-and-mapping-files
EF and ObjectContext
"%windir%\Microsoft.NET\Framework\v4.0.30319\edmgen.exe" /mode:fullgeneration /c:"Data Source=222.255.38.14;Initial Catalog=DBWC;User ID=sa;Password=92pU7nxa" /project:MVCTutorial.Repository /entitycontainer:MVCTutorialEntitiesContainer /namespace:MVCTutorial.Repository /language:CSharp
Notes:
+ ObjectContext can be used by Entity Framework 4.0 and below.
+ The ObjectContext class is not thread-safe.
EF and DbContext + DbSet
Create Entity Data Model:
http://www.entityframeworktutorial.net/entityframework5/create-dbcontext-in-entity-framework5.aspx
Required:
+ .NET Framework 4.5
+ Add > New Item of ADO.NET Entity Data Model
+ Name: School, Project: MVCTutorial.Repository , EntityContainer: MVCTutorialEntitiesContainer
+ Entity Data Model (School.edmx file)
+ Etc: School.edmx and see two important files, School.Context.tt and School.tt
Notes:
+ DBContext can be used by Entity Framework 4.1 and above.
+ Any public static (C#) or Shared (Visual Basic) members of DbContext are thread-safe. Any instance members are not guaranteed to be thread safe.
EF5 & DbContext
https://lkdev.wordpress.com/2016/10/10/series-ve-entity-framework-phan-5-dbcontext/
Read more:
https://www.c-sharpcorner.com/UploadFile/ff2f08/objectcontext-vs-dbcontext
https://stackoverflow.com/questions/10126871/entity-framework-generating-classes/10246880
https://stackoverflow.com/questions/7018350/using-both-objectcontext-and-dbcontext
Cách dùng:
using (var ctx = new SchoolDBEntities())
{
//Can perform CRUD operation using ctx here..
}
using (var ctx = new SchoolDBEntities())
{
var objectContext = (ctx as System.Data.Entity.Infrastructure.IObjectContextAdapter).ObjectContext; //use objectContext here..
}
EF 6
1. Go to Tools -> Get Tools and features
2. Select Individual components tab and check Entity Framework 6 tools under SDK's, libraries, and framework section
EF 6 - Entity Framework 6 Tools - Missing ADO.NET Entity Data Model template in VS2017
it looks like the Entity Framework 6 Tools component wasn't selected when you installed. By default, this will be installed if you select the .NET desktop development or ASP.NET and web development workloads on the main install screen (though you can also unselect it under these workloads). If you don't use either of those workloads, you can always (as you did) install it individually from the Individual components tab.
https://stackoverflow.com/questions/42877898/entity-framework-not-appearing-in-add-new-item-list-in-visual-studio-2017
You’re All Doing Entity Framework Wrong
https://medium.com/@hoagsie/youre-all-doing-entity-framework-wrong-ea0c40e20502
EF Core
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
https://docs.microsoft.com/en-us/ef/core/get-started/aspnetcore/existing-db
https://www.learnentityframeworkcore.com/walkthroughs/existing-database