I just started looking at Dapper.net and just experimented with some different queries, one of which produces strange results that I did not expect.
I have 2 tables - Photosand PhotoCategoriesthat are related toCategoryID
Photo table
PhotoId (PK - int)
CategoryId (FK - smallint)
UserId (int)
Photo Category Table
CategoryId (PK - smallint)
CategoryName (nvarchar(50))
My 2 classes:
public class Photo
{
public int PhotoId { get; set; }
public short CategoryId { get; set; }
public int UserId { get; set; }
public PhotoCategory PhotoCategory { get; set; }
}
public class PhotoCategory
{
public short CategoryId { get; set; }
public string CategoryName { get; set; }
{
I want to use multi-mapping to return an instance Photowith a filled instance associated PhotoCategory.
var sql = @"select p.*, c.* from Photos p inner
join PhotoCategories c
on p.CategoryID = c.CategoryID where p.PhotoID = @pid";
cn.Open();
var myPhoto = cn.Query<Photo, PhotoCategory, Photo>(sql,
(photo, photoCategory) => { photo.PhotoCategory = photoCategory;
return photo; },
new { pid = photoID }, null, true, splitOn: "CategoryID").Single();
When this is done, not all properties are filled (despite the same names between the database table and my objects.
I noticed that if I don'tchoose p. * etc. in mine SQLand instead.
I explicitly specify the fields.
EXCLUDING p.CategoryId , ( , , CategoryId Photo, select).
, , , SQL, .
CategoryID Photo Photo.PhotoCategory.CategoryId, .
PhotoCategory,
.
- , ? Dapper?