开发者

EF4 Code Only - Map Columns to Property Complex type

开发者 https://www.devze.com 2023-01-23 09:45 出处:网络
I have a table like this: Name Tree Iron Clay 开发者_Go百科Added I want to map it to a model like this:

I have a table like this:

I want to map it to a model like this:

  • Name
  • Resources
    • Tree
    • Iron
    • Clay
  • Added

In makes sense to map it like this, when working with it in my program, but doing it that way in the databse would just make it more complex ... not would not add any useful things.

Is it possible with EF4 Code ONly?


public class Sample
{
   public int Id { get; set;}  // primary key required
   public string Name {get;set;}
   public DateTime Added{get;set;}

}

 public class Resource
 {
      //  no Id defined here
      public string Tree{get;set;}
      public string Iron { get;set;}
      public string Clay { get;set;}
  }

 public class SampleDB : DbContext
 {
      //public DbSet<Resource> Resources { get; set; } // should not be there
        public DbSet<Sample> Samples { get; set; }
 }
0

精彩评论

暂无评论...
验证码 换一张
取 消