I have two C# classes
public class SearchResult
{
public int? EntityId { get; set; }
public string Name { get; set; }
public Address RegisteredAddress { get; set; }
}
and
public class Address
{
public int? AddressId { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Address3 { get; set; }
}
this is used in a dbContext call to map out the returning objects from a database via EF5
using (DbEntities db = new DbEntities())
{
querySearchResult = db.Database.SqlQuery<SearchResult>(
@"SELECT e.entity_id AS EntityId, e.entity_reg_name AS Name,
a.address_1 AS [RegisteredAddress.Address1]
FROM
entity AS e
LEFT JOIN address AS a ON e.entity_reg_addr_id = a.address_id",
objectParameterList.ToArray()).ToList();
}
The problem I'm having is that I cant seem to get the address object mapped even though there is address data returned. The other properties of the searchResult map fine.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…