2014-03-04 33 views
1

我在VS使用MVC脚手架+ EF6在Web applicatioon项目2013年脚手架未检测Complext类型属性的实体

域类(entites的)和上下文(DbContext)是通过引用两个独立的项目Web项目。

我有一个Patient类,它具有如下的复杂属性。

public class Patient 
{ 
    public int PatientId { get; set; } 

    // Some properties 

    // Complex property 
    public MyComplexType Complex { get; set; } 
} 

public class MyComplexType 
{ 
    public SomeType Property1 { get; set; } 
    public SomeOtherType Property2 { get; set; } 
} 

问题:

MVC脚手架引擎没有检测到复杂的财产Patient类和生成的视图不包含字段,以显示或编辑属性。我尝试装饰MyComplexType类与ComplexType属性,但它没有奏效。

可以做些什么?

回答

0

根据this post和Julie Lerman的书编程实体框架:代码优先,复杂类型只能包含原始属性。

普通复合类型规则

  1. 复杂类型没有关键属性。
  2. 复杂类型只能包含基本属性。
  3. 当用作另一个类中的属性时,该属性必须代表一个单一的 实例。它不能是一个集合类型。

在我来说,我使用一种非常规的复杂类型,所以我应该装饰MyComplexTypeComplexType属性了。

public class Patient 
{ 
    public int PatientId { get; set; } 

    // Some properties 

    // Complex property 
    public MyComplexType Complex { get; set; } 
} 

[ComplexType] 
public class MyComplexType 
{ 
    public SomeType Property1 { get; set; } 
    public SomeOtherType Property2 { get; set; } 
} 


public class SomeType 
{ 
    // primitive properties here 
} 

public class SomeOtherType 
{ 
    // primitive properties here 
} 

HTH