天天看點

System.ComponentModel.DataAnnotations.Schema 沖突System.ComponentModel.DataAnnotations.Schema 沖突

System.ComponentModel.DataAnnotations.Schema 沖突

Entity Framework 與 .net4.5 的 System.ComponentModel.DataAnnotations 都有 System.ComponentModel.DataAnnotations.Schema 命名空間。并且都有一些相同的 特性(Attribute), 如:ForeignKeyAttribute, NotMappedAttribute 等。當項目同時引用了 EntityFramework.dll 與 System.ComponentModel.Composition.dll ,你将不能正常使用上面提到的特性。

使用别名,給這兩個dll 加一個不同的根。

  • 引用dll, 預設的别名都是 global
  • 将 EntityFramework.dll 的别名改為 EF
  • 在類的using 區域寫入 extern alias EF;
  • *using EF::System.ComponentModel.DataAnnotations.Schema 引用别名加命名空間
  • *
    System.ComponentModel.DataAnnotations.Schema 沖突System.ComponentModel.DataAnnotations.Schema 沖突
    *

繼續閱讀