Does EF SqlQuery has Multi-Mapping feature something like in Dapper?
See: Fill list object using dapper c#
EF join queries results are not as I expected.
Example:
Models:
public class Tlb
{
[Key]
public int TlbId { get; set; }
public bool IsPublished { get; set; }
public virtual ICollection<TlbAttachment> Attachments { get; set; }
public virtual ICollection<TlbAttachment> OtherCollection1 { get; set; }
public virtual ICollection<TlbAttachment> OtherCollection2 { get; set; }
}
public class TlbAttachment
{
[Key, Column(Order = 0)]
public int AttachmentId { get; set; }
[ForeignKey("AttachmentId")]
public virtual Attachment Attachment { get; set; }
[Key, Column(Order = 1)]
public int TlbId { get; set; }
[ForeignKey("TlbId")]
public virtual Tlb Tlb { get; set; }
}
public class Attachment
{
[Key]
public int AttachmentId { get; set; }
public int Type { get; set; }
}
DB access:
const string query = "SELECT * " +
"FROM Tlb AS t LEFT OUTER JOIN "+
"TlbAttachment AS at ON at.TlbId = t.TlbId LEFT OUTER JOIN "+
"Attachment AS a ON a.AttachmentId = at.AttachmentId " +
"WHERE t.IsPublished = 1 AND a.Type = 0";
return _DbContext.Database.SqlQuery<Model.Tlb>(query);
The result of SqlQuery
doesn't contain Attachments
and I don't want to get OtherCollection1 and OtherCollection2. Which seems in Dapper you can change its mapping.
Using Include
in Web API, both OtherCollection1 and OtherCollection2 will be called in lazy-loading mode. And I don't need them.