我有两个子类,我需要将List元素复制到主对象
public Class Foo1 : Anote
{
public bool Ison { get; set;}
public List<Anote>Anotes { get; private set;}
public Foo1()
{
this.Anotes = new List<Anote>();
}
}
public Class Foo2 : Bnote
{
public bool Ison { get; set;}
public List<Bnote>Anotes { get; private set;}
public Foo2()
{
this.Anotes = new List<Bnote>();
}
}
public Class Foo3 : Cnote
{
public bool Ison { get; set;}
public List<Cnote>Anotes { get; private set;}
public List<Cnote>Bnotes { get; private set; } …Run Code Online (Sandbox Code Playgroud) 我有2张桌子,说T1和T2。T1包含oID,cID,日期,状态,并T2包含cID,cName,cURL。我为上面的2个表设计了类,如下所示:
T1.cs
public class T1{
public int oID{get;set;}
public int cID{get;set;}
public DateTime date{get;set;}
public string status{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
T2.cs
public class T2{
public int cID{get;set;}
public string cName{get;set;}
public string cURL{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
cID在T1是foreign key指T2 - cID
现在,我有我的T3视图模型如下结合T1和T2
T3.cs
public class T3:T1
{
public int cID{get;set;}
public string cName{get;set;}
public string cURL{get;set;}
}
Run Code Online (Sandbox Code Playgroud)
T3扩展T1和T2 …
我有一个 .Net 5 Web Api 项目并想使用
地图大师 v7.2.0
以避免手动映射对象。以下代码显示了示例场景
。
[ApiController]
[Route("[controller]")]
public class MyController : ControllerBase
{
[HttpGet]
public ActionResult<UsernameWithTodoTitle> Get()
{
TypeAdapterConfig<(User, Todo), UsernameWithTodoTitle>
.NewConfig()
.Map(dest => dest, src => src.Item1) // map everything from user
.Map(dest => dest, src => src.Item2) // map everything from todo
.Map(dest => dest.TodoTitle, src => src.Item2.Title); // map the special fields from todo
var user = new User { Username = "foo", FieldFromUser = "x" };
var todo …Run Code Online (Sandbox Code Playgroud)