entity-framework-5

Selectively Disabling Cascade Delete on Many-to-Many Link Table

放肆的年华 提交于 2020-01-13 08:49:31
问题 Is it possible to selectively remove the Cascade Delete option on an automatically-generated many-to-many link table in Entity Framework 5 Code First? Here's a simple example which needs it: public class Parent { public int Id { get; set; } public virtual IList<ChildA> As { get; set; } public virtual IList<ChildB> Bs { get; set; } } public class ChildA { public int Id { get; set; } [Required] public virtual Parent Parent { get; set; } public virtual IList<ChildB> ChildBJoins { get; set; } }

Entity Framework 5 - Enum based Discriminator for derived classes

孤者浪人 提交于 2020-01-12 14:34:09
问题 I have the following (abbreviated for clarity) - an enum, a base class with that enum, and two derived classes that set the enum to a specific value. public enum MyEnum { Value1, Value2 } public class MyBaseClass { public MyEnum { get; protected set; } } public class DerivedOne: MyBaseClass { public DerivedOne { MyEnum = MyEnum.Value1; } } public class DerivedTwo: MyBaseClass { public DerivedTwo { MyEnum = MyEnum.Value2; } } What I want to do, is have Entity Framework 5 automatically

Map tables relationship from legacy database w/ entity framework with only primary keys

Deadly 提交于 2020-01-11 12:14:29
问题 data (table name) dataid PK, value1, value2, value3 data_address (table name) dataaddressid PK, dataid - id to errenddataid, addressid1 - id to en addressid, addressid2 - id to en addressid, type address (table namne) addressid PK - id to addressid1 or addressid2, address1, address2, name, zipcode, city I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that! 回答1: If you are certain that the database

Map tables relationship from legacy database w/ entity framework with only primary keys

回眸只為那壹抹淺笑 提交于 2020-01-11 12:13:51
问题 data (table name) dataid PK, value1, value2, value3 data_address (table name) dataaddressid PK, dataid - id to errenddataid, addressid1 - id to en addressid, addressid2 - id to en addressid, type address (table namne) addressid PK - id to addressid1 or addressid2, address1, address2, name, zipcode, city I have a really hard time trying to map this relations using Entity Framework 5, if some one have an idea or good links I would much appreciate that! 回答1: If you are certain that the database

Entity framework Invalid Column name, EF adds numer 1 to primary key

旧街凉风 提交于 2020-01-11 04:50:06
问题 I have these two entities: public partial class Suscriptores { public Suscriptores() { this.Publicacion = new HashSet<Publicacion>(); } [Key] public int IdSuscriptor { get; set; } public string LogoSuscriptor { get; set; } public string Identificacion { get; set; } public string Nombre { get; set; } public string Direccion { get; set; } public string Telefono { get; set; } public string Email { get; set; } public string Fax { get; set; } public string Home { get; set; } public virtual

AddOrUpdate works not as expected and produces duplicates

喜欢而已 提交于 2020-01-10 21:20:27
问题 I'm using Code-First DBContext-based EF5 setup. In DbMigrationsConfiguration.Seed I'm trying to fill DB with default dummy data. To accomplish this task, I use DbSet.AddOrUpdate method. The simplest code to illustrate my aim: j = 0; var cities = new[] { "Berlin", "Vienna", "London", "Bristol", "Rome", "Stockholm", "Oslo", "Helsinki", "Amsterdam", "Dublin" }; var cityObjects = new City[cities.Length]; foreach (string c in cities) { int id = r.NextDouble() > 0.5 ? 0 : 1; var city = new City {

Is adding a class that inherits from something a violation of the solid principles if it changes the behavior of code?

£可爱£侵袭症+ 提交于 2020-01-09 07:40:26
问题 I struggled to enable my code to run code first EF migrations using different connection strings, and finally got it working. The method I used is outlined in my answer to this question What bothers me is that in order to be able to run the same code using different connection strings I had to 1) Resort to a global setting to store the connection string 2) Introduce a class whose very presence caused the code to behave differently. This is so different to the way I am used to working. Is the

Double foreign key generation

喜你入骨 提交于 2020-01-06 19:40:28
问题 This is a followup-question of this question, where i had a similar problem. But this is solved now by default foreign key convention. My problem now is (in short), that my migrations generates int ReferencedEntityID; int ReferencedEntity_ReferencedEntityID; where one is an integer property in my model and the other one is a virtual property. My migrations generates this: "dbo.Contracts", c => new { ContractId = c.Int(nullable: false, identity: true), PricePerUnit = c.Double(nullable: false),

Double foreign key generation

二次信任 提交于 2020-01-06 19:40:07
问题 This is a followup-question of this question, where i had a similar problem. But this is solved now by default foreign key convention. My problem now is (in short), that my migrations generates int ReferencedEntityID; int ReferencedEntity_ReferencedEntityID; where one is an integer property in my model and the other one is a virtual property. My migrations generates this: "dbo.Contracts", c => new { ContractId = c.Int(nullable: false, identity: true), PricePerUnit = c.Double(nullable: false),

Entity Framework DbSet contains 0 records

自闭症网瘾萝莉.ら 提交于 2020-01-06 15:18:41
问题 So I have the following problem: I have some Vehicle entity that corresponds to a table in the DB. But when I try to retrieve ALL the records with the following line : var vehicles = db.VehicleSet.ToList(); I get ZERO objects as result ... whilst the table in the DB has approx. 18k records. Any idea where the problem might be, or is the question too vague? 回答1: I Figured it out. Turns out it was a problem with the Database. In my structure I was using a "Discriminator" field which was not set