如何将查询结果映射到成员类

时间:2016-03-17 16:33:39

标签: c# sql sql-server

我有两个班级

public class A
{
    public string Name { get; set; }
}

public class B
{
    public int Id { get; set; }
    public A MemberA { get;set; }
}

如何正确地进行查询以将结果映射到所有成员?

var query = "SELECT [Table1].[Id] as [Id], [Table2].[Name] as [Member_A].[Name] FROM [Table1]"; // this is more complex query, there are more tables, columns, joins
ObjectResult<B> result = _context.ObjectContext.ExecuteStoreQuery<B>(query);

这不起作用。 result.MemberA为空。如何制作?

0 个答案:

没有答案