entity-framework

EntityFramework Core relation to composite key

强颜欢笑 提交于 2020-02-01 04:09:27
问题 Consider the following database tables. Unfortunately the tables cannot be altered in any way. Houses has an auto-increment ID field named Id , a string field named Name and an integer field named AreaId . The latter is not a foreign key to the Areas table. Areas has a composite key consisting of AreaId , CountryId and LangId . An Area with the same AreaId can exist but with different CountryId and LangId . E.g.: There can be two rows with the same AreaId but different LangId . NOTE: Why does

How to generalise access to DbSet<TEntity> members of a DbContext?

旧街凉风 提交于 2020-02-01 03:37:09
问题 I have a DbContext with several of the following type of members: public DbSet<JobLevel> JobLevels { get; set; } public DbSet<Country> Countries { get; set; } public DbSet<Race> Races { get; set; } public DbSet<Language> Languages { get; set; } public DbSet<Title> Titles { get; set; } All these are where T: IdNamePairBase , which has Id and Name members only. I am trying desperately to find a common interface with which to access any of these members, to generalise the following MVC3

Manually Provide DbContext to DbMigrator

十年热恋 提交于 2020-01-31 15:07:12
问题 Platform .NET 4.5 and Entity Framework 6. Question I have the following code to execute a Migration: //The following function just returns an object of the Configuration() class //generated by code migrations var migratorConfig = currentMigrationProvider.CreateDbMigrationConfiguration(); var dbMigrator = new System.Data.Entity.Migrations.DbMigrator(migratorConfig); dbMigrator.Update(); The problem is that Update() function tries to create an instance of my DbContext class and for a few good

Manually Provide DbContext to DbMigrator

会有一股神秘感。 提交于 2020-01-31 15:06:53
问题 Platform .NET 4.5 and Entity Framework 6. Question I have the following code to execute a Migration: //The following function just returns an object of the Configuration() class //generated by code migrations var migratorConfig = currentMigrationProvider.CreateDbMigrationConfiguration(); var dbMigrator = new System.Data.Entity.Migrations.DbMigrator(migratorConfig); dbMigrator.Update(); The problem is that Update() function tries to create an instance of my DbContext class and for a few good

Manually Provide DbContext to DbMigrator

邮差的信 提交于 2020-01-31 15:04:27
问题 Platform .NET 4.5 and Entity Framework 6. Question I have the following code to execute a Migration: //The following function just returns an object of the Configuration() class //generated by code migrations var migratorConfig = currentMigrationProvider.CreateDbMigrationConfiguration(); var dbMigrator = new System.Data.Entity.Migrations.DbMigrator(migratorConfig); dbMigrator.Update(); The problem is that Update() function tries to create an instance of my DbContext class and for a few good

Check if Record Exists in Entity Framework [duplicate]

爷,独闯天下 提交于 2020-01-31 06:28:26
问题 This question already has answers here : Best way to check if object exists in Entity Framework? (9 answers) Closed 5 years ago . Could somebody please tell me how I check to see if a record exists, if it does exists then do nothing and if it doesn't then add the record to the database? Please see my code below: if (isIpnValidated == true) { using (WebApplication1Entities db = new WebApplication1Entities()) { Orders order = new Orders(); order.UserId = userId; order.Date = System.DateTime.Now

Check if Record Exists in Entity Framework [duplicate]

自作多情 提交于 2020-01-31 06:26:22
问题 This question already has answers here : Best way to check if object exists in Entity Framework? (9 answers) Closed 5 years ago . Could somebody please tell me how I check to see if a record exists, if it does exists then do nothing and if it doesn't then add the record to the database? Please see my code below: if (isIpnValidated == true) { using (WebApplication1Entities db = new WebApplication1Entities()) { Orders order = new Orders(); order.UserId = userId; order.Date = System.DateTime.Now

Check if Record Exists in Entity Framework [duplicate]

时间秒杀一切 提交于 2020-01-31 06:25:42
问题 This question already has answers here : Best way to check if object exists in Entity Framework? (9 answers) Closed 5 years ago . Could somebody please tell me how I check to see if a record exists, if it does exists then do nothing and if it doesn't then add the record to the database? Please see my code below: if (isIpnValidated == true) { using (WebApplication1Entities db = new WebApplication1Entities()) { Orders order = new Orders(); order.UserId = userId; order.Date = System.DateTime.Now

Check if Record Exists in Entity Framework [duplicate]

自作多情 提交于 2020-01-31 06:25:29
问题 This question already has answers here : Best way to check if object exists in Entity Framework? (9 answers) Closed 5 years ago . Could somebody please tell me how I check to see if a record exists, if it does exists then do nothing and if it doesn't then add the record to the database? Please see my code below: if (isIpnValidated == true) { using (WebApplication1Entities db = new WebApplication1Entities()) { Orders order = new Orders(); order.UserId = userId; order.Date = System.DateTime.Now

Entity Framework - Include multiple level properties

只愿长相守 提交于 2020-01-31 05:33:22
问题 I am trying to get a table from database using entity framework. The table has reference to other table which again has reference to other tables. I know how to include other tables. And according to this answer and this MSDN page including multiple levels are like this: entity.TableLevel1.Include(tLvl1=>tLvl1.TableLevel2.Select(tLvl2=>tLvl2.TableLevel3)); But my question is, how to include another table at level 3 ? This seems not to work: entity.TableLevel1 .Include(tLvl1=>tLvl1.TableLevel2