表[注意]
Id int
描述nvarchar(255)
ClassName nvarchar(50)
ClassId int
表[用户]
Id int
FullName nvarchar(255)
启用位
地址nvarchar(255)
电子邮件nvarchar(255)
表格[客户]
Id int
CompanyName nvarchar(255)
PhoneNumber nvarchar(255)
地址nvarchar(255)
电子邮件nvarchar(255)
以下课程:
public class User{
public int Id { get; set; }
public string FullName { get; set; }
public bool Enable { get; set; }
public string Address { get; set; }
public string Email { get; set; }
}
public class Client{
public int Id { get; set; }
public string CompanyName { get; set; }
public string PhoneNumber { get; set; }
public string Address { get; set; }
public string Email { get; set; }
}
public class Note{
public int Id { get; set; }
public string Description { get; set; }
public string ClassName { get; set; }
public int ClassId { get; set; }
public virtual User { get; set; } <-- Populate depending on the ClassName and ClassId fields
public virtual Client { get; set; } <-- Populate depending on the ClassName and ClassId fields
}
表注释示例
╔════╦═════════════╦═══════════╦═════════╦
║ id ║ Description ║ ClassName ║ ClassId ║
╠════╬═════════════╬═══════════╬═════════╬
║ 1 ║Test Note 1 ║ Client ║ 2544 ║
╠════╬═════════════╬═══════════╬═════════╬
║ 2 ║Test Note 2 ║ User ║ 25 ║
╠════╬═════════════╬═══════════╬═════════╬
║ 3 ║Test Note 3 ║ Client ║ 2578 ║
╚════╩═════════════╩═══════════╩═════════╩
请注意,在note类中有两个对象
public virtual User {get;组; }
公共虚拟客户端{get;组; }
我需要做的是在用户或客户端这两个表中的一个注意中进行映射,具体取决于 ClassName 字段。因此,实体应该知道在哪个表中查找信息。
如果在 ClassName 字段中&#34;客户端&#34; ,则会填充客户端对象,如果它是&#34 ;用户&#34; 它应填充用户对象。
是否可以使用Entity Framework执行此操作?