0

我有一个关于使用 MVC 的 EF Code First 的问题。目前我知道如何创建控制器并查看一个模型,该模型具有所有属性作为本机类型,例如(int、string 等)。

如果我有一个模型,它的一个属性是在我的项目的另一个模型中定义的类型怎么办?

就像是

public class Partido
    {
        public int ID { get; set; }
        public Seleccion Local { get; set; }
        public Seleccion Visitante { get; set; }
        public Resultado Marcador { get; set; }
    }

其中SeleccionResultado在项目的同一模型命名空间中分别定义。

4

1 回答 1

1

用属性装饰SeleccionResultado分类。ComplexType例子:

public class Partido
{
    public int ID { get; set; }
    public Seleccion Local { get; set; }
    public Seleccion Visitante { get; set; }
    public Resultado Marcador { get; set; }
}

[ComplexType]
public class Seleccion {} 

[ComplexType]
public class Resultado {}

实体框架将在“Partido”表中生成SeleccionResultado类属性相对应的适当列。

您可以在此处了解更多信息:Code First Data Annotations

于 2012-06-08T13:12:03.887 回答