Creating Entities First of all, Let's create some entities to have a test. Create a project Add following packages by NuGet EntityFramework MySql.Data.Entity (I'm just using MySql, it's not necessary) Add some codes: class Class { public int ClassId…
There are three types of relationships in database. They are: One-to-Many One-to-One Many-to-Many The One-to-Many relationship Write some codes first: class Company { public int CompanyId { get; set; } [MaxLength(50)] public string CompanyName { get;…
INDEX Updating Data The IGNORE Keyword Deleting Data Faster Deletes Guidelines for Updating and Deleting Data Updating Data UPDATE customers SET cust_name = 'The Fudds', cust_email = 'elmer@fudd.com' ; To delete a column's value, you can set it to NU…
The default Way to handle concurrency of Entity Framework is using optimistic concurrency. When two clinets update the same entity, one of theirs data will be lost without any notify. Some times, the client want to know if his data has been saved suc…
Sometimes, you need to find some data in an existing context instead of the database. By befault, Entity Framework always find data in database. If you want to find data which have loaded in memory, please do it like this: Frist of all, let's insert…
There are three ways to define the database structure by Entity Framework API. They are: Attributes The DbModelBuilder API Configuration Classes Attributes We can Add some attributes for entities or proteries to configure database structures. For exa…
Sometimes, you have created two models. They have the same parent class like this: public class Person { public int PersonId { get; set; } public string PersonName { get; set; } } public class InsidePerson : Person { public string Title { get; set; }…
错误信息: “System.Data.Entity.Core.EntityCommandExecutionException”类型的异常在 EntityFramework.SqlServer.dll 中发生,但未在用户代码中进行处理. 其他信息:执行命令定义时出错.有关详细信息,请参阅内部异常. 跟踪代码找到详细信息: Entity Framework已有打开的与此Command相关联的DataReader,必须首先将它关闭. EF内部是使用DataReader作为资料存取,所以如果没关闭连接就…
Complex types are classes that map to a subset of columns of a table.They don't contains key. They are the Value Objects. For example, you have a entity named Company: public class Company { public int CompanyId { get; set; } public string CompanyNam…
Sometimes, We want to check the original sql statements. creating a commandInterceptor is a good way to do this. Add a class named MyCommandInterceptor class MyCommandInterceptor: DbCommandInterceptor { public override void NonQueryExecuted(DbCommand…