我需要将复杂类型关系映射到许多表



好的,我有这个类'Opciones',很抱歉它是西班牙语的。要理解的主要事情是我有这个类"Opciones",它在"Registro"中有多个自身实例,我找不到一种方法将其与实体框架映射,我正在使用迁移,因为我必须坚持数据库的结构。我让它从数据库中检索数据,但是当它到达复杂类型的字段时,它只会在属性值内带来 null 和 0。

我尝试在 OnModelCreate 方法中配置映射,没有任何效果,它最终要求像 tipoClienteId 列这样的"propertyNameId",我希望它做的是继续搜索 opciones 表并根据属性中找到的 id 检索信息,但对于我的应用程序来说,它是一个类的属性,它是一个对象。这是我第一次处理实体框架和映射,因此对此事的任何澄清都受到好评。

public class Registro
{
public int Id { get; set; }
public string usuarioRed { get; set; }
public DateTime fechaLlamada { get; set; }
public DateTime fechaDevolucion { get; set; }
public Opciones tipoCliente { get; set; }
public Opciones motivoDevolucion { get; set; }
}
public class Opciones
{
public int Id { get; set; }
public string descripcion { get; set; }
public Boolean activo { get; set; }
public int idDependencia { get; set; }
}

对于实体框架,若要在实体之间创建关系,必须添加 ID 和对象

public class Registro
{
public int Id { get; set; }
public string usuarioRed { get; set; }
public DateTime fechaLlamada { get; set; }
public DateTime fechaDevolucion { get; set; }
public int tipoClienteId { get; set; }
public Opciones tipoCliente { get; set; }
public int motivoDevolucionId { get; set; }
public Opciones motivoDevolucion { get; set; }
}

最新更新