我正在使用 Dapper.net Extensions,我希望能够检索一个 Photo 对象并将“this”设置为它,而不必单独设置每个属性。实现这一目标的最佳方法是什么?在下面的代码中,它说我不能分配给“this”,因为它是只读的。
public class Photo
{
public Int32 PhotoId { get; set; }
public Guid ObjectKey { get; set; }
public Int16 Width { get; set; }
public Int16 Height { get; set; }
public EntityObjectStatus ObjectStatus { get; set; }
public PhotoObjectType PhotoType { get; set; }
public PhotoFormat2 ImageFormat { get; set; }
public Int32 CategoryId { get; set; }
public Photo(int pPhotoId)
{
Load(pPhotoId);
}
public void Load(int pPhotoId)
{
using (SqlConnection conn = new SqlConnection(Settings.Conn))
{
conn.Open();
this = conn.Get<Photo>(pPhotoId);
}
}
}