ef-code-first

Entity Framework Code First and Classes that Implement IList<T>

谁说我不能喝 提交于 2020-01-11 12:09:10
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected

Entity Framework Code First and Classes that Implement IList<T>

泄露秘密 提交于 2020-01-11 12:09:05
问题 I have a ComplexType that must implement IList<T> (background info here). Unfortunately, Entity Framework complains about the indexed property required of that interface [NotMapped] public T this[int index] (Note it's decorated with the NotMapped data annotation). I get a DbUpdateException at runtime with the inner exception Indexed properties are not supported. If I comment out that the class implements IList<T> and comment out the indexed property, instances of the class persist as expected

Mapping many to many relationship

元气小坏坏 提交于 2020-01-11 10:27:07
问题 I am have some trouble getting Entity Framework to handle a many to many relationship in my data schema. Here is my model: public class User { public int UserId { get; set; } public int Username { get; set; } public IEnumerable<Customer> Customers { get; set; } ... } public class Customer { public int CustomerId { get; set; } ... } public class CustomerUser { public int CustomerUserId { get; set; } public int CustomerId { get; set; } public int UserId { get; set; } public DateTime

How map single entity with multiple table

こ雲淡風輕ζ 提交于 2020-01-11 10:07:48
问题 I want to get data from two tables with single Entity class. How?? public class HomeViewModel { [Key] [Column("candidate_ID")] public int candidateID { get; set; } [Column("first_name")] public string firstName { get; set; } [Column("last_name")] public string lastName { get; set; } public string emailID { get; set; } public string mb_country_code { get; set; } public int mobile_no { get; set; } } Above entity class holds 6 property where 3 property represents one table1 and 3 represents

How map single entity with multiple table

和自甴很熟 提交于 2020-01-11 10:07:33
问题 I want to get data from two tables with single Entity class. How?? public class HomeViewModel { [Key] [Column("candidate_ID")] public int candidateID { get; set; } [Column("first_name")] public string firstName { get; set; } [Column("last_name")] public string lastName { get; set; } public string emailID { get; set; } public string mb_country_code { get; set; } public int mobile_no { get; set; } } Above entity class holds 6 property where 3 property represents one table1 and 3 represents

How to drop a table in Entity Framework Code First?

 ̄綄美尐妖づ 提交于 2020-01-11 08:22:28
问题 I am using Entity Framework with Auto Migrations. So when I add a new model to my Context, my database is updated and new table is created. What I want to do is the opposite, droping the table completely from database. However, removing the definition from Context class does not work. public class CompanyContext : DbContext { public DbSet<Permission> Permissions { get; set; } public DbSet<Company> Companies { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) {

EF model with code first independent association or foreign key association

百般思念 提交于 2020-01-11 06:43:08
问题 I have read the articles about Independent association from Ladislav. I have checked the information he provided in this link. The information is quite helpful and it shed some light. However I want to model my existing database which I was given access to. It has three tables Users, Certificates and Quiz . At first I thought of modeling as independent association. Why? My Users table has primary key UserID and Certificates table has PK CertID and a column UserID which I can say is a foreign

One or Zero to One Entity Framework Code First FluentApi

梦想的初衷 提交于 2020-01-11 02:08:53
问题 I need to create fluentapi one or zero to one reference and have navigation properties on both of entities. EntityTwo should contain simple proerty to store foreign key (EntityOneId) public class EntityOne { public int Id { get; set; } public EntityTwo EntityTwo { get; set; } } public class EntityTwo { public int Id { get; set; } public int EntityOneId { get; set; } public EntityOne EntityOne { get; set; } } public class MyDbContext : DbContext { protected override void OnModelCreating

Problems creating a Foreign-Key relationship on Entity Framework

强颜欢笑 提交于 2020-01-10 08:10:52
问题 i'm having trouble configuring a foreign key relationship in my Entity Framework fluent Api: Here is the head of the report: public class Testata { public Testata() { Details = new List<Dettaglio>(); } public virtual int IDTEST { get; set; } public virtual string Value { get; set; } public virtual int IDDETAIL { get; set; } public virtual string IDTESTALT { get; set; } public virtual byte[] BLOB { get; set; } public virtual IList<Dettaglio> Details { get; set; } } This is the report's detail

Problems creating a Foreign-Key relationship on Entity Framework

六眼飞鱼酱① 提交于 2020-01-10 08:10:07
问题 i'm having trouble configuring a foreign key relationship in my Entity Framework fluent Api: Here is the head of the report: public class Testata { public Testata() { Details = new List<Dettaglio>(); } public virtual int IDTEST { get; set; } public virtual string Value { get; set; } public virtual int IDDETAIL { get; set; } public virtual string IDTESTALT { get; set; } public virtual byte[] BLOB { get; set; } public virtual IList<Dettaglio> Details { get; set; } } This is the report's detail