0

我有一张这样的桌子:

  • 姓名
  • 粘土
  • 添加

我想将它映射到这样的模型:

  • 姓名
  • 资源
    • 粘土
  • 添加

在我的程序中使用它时,像这样映射它是有意义的,但是在数据库中这样做只会使它更复杂......不会添加任何有用的东西。

是否可以仅使用 EF4 代码?

4

1 回答 1

1
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; }
 }
于 2010-12-21T13:10:12.583 回答