I have a problem displaying an existing database.
2 tables (simplified)
"SomeEntity" Id int Name nvarchar
and
"EntityProperty" EntityId int Name nvarchar
and are related one-to-many from Entity to entity properties.
How can I match this using the first EF 4.1 code?
thanks in advance.
Edited 1:
ok) this is my code
class Program { static void Main(string[] args) { var context = new DataContext(); var result = context.SomeEntity.Include(p => p.EntityProperties); foreach (var entity in result) { Console.WriteLine(entity); } } } public class SomeEntity { public int EntityId { get; set; } public string Name { get; set; } public virtual ICollection<EntityProperty> EntityProperties { get; set; } public override string ToString() { return string.Format("Id: {0}, Name: {1}", EntityId, Name); } } public class EntityProperty { public int EntityId { get; set; } public string Name { get; set; } } public class DataContext : DbContext { public DbSet<SomeEntity> SomeEntity { get { return this.Set<SomeEntity>(); } } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<SomeEntity>().ToTable("SomeEntity"); modelBuilder.Entity<SomeEntity>().HasKey(k => k.EntityId); modelBuilder.Entity<EntityProperty>().ToTable("EntityProperty"); modelBuilder.Entity<EntityProperty>().HasKey(k => k.EntityId); } }
The problem is when I use Include in the request to get properties:
Invalid column name 'SomeEntity_EntityId'. Invalid column name "SomeEntity_EntityId".
source share