【问题标题】:EF4 Code Only - Map Columns to Property Complex type仅 EF4 代码 - 将列映射到属性复杂类型
【发布时间】:2010-12-21 21:10:12
【问题描述】:

我有一张这样的桌子:

  • 姓名
  • 粘土
  • 已添加

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

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

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

是否可以仅使用 EF4 代码?

【问题讨论】:

    标签: orm ef4-code-only


    【解决方案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; }
     }
    

    【讨论】:

    • 嗯,是的......现在可以使用 EF4 CTP5。就像你写的那样。忘记这一切。感谢上帝的邮件通知:-)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    相关资源
    最近更新 更多