In a Dapper ORM application, I want to assign one object to another, or all data members at once. Like this:
public class TableA
{
public int UserId { get; set; }
public string ClientId { get; set; }
// ... more fields ...
public bool Query()
{
bool Ok = false;
try{
// Method A
TableA Rec = QueryResultRecords.First();
MyCopyRec(Rec, this); // ugly
// Method B
this = QueryResultRecords.First(); // avoids CopyRec, does not work
Ok = true;
}
catch(Exception e){
Ok = false;
}
return Ok;
}
}
With Method A you can assign the object from .First()
directly to a new object of class TableA
, and need a custom method MyCopyRec
to get the data in the data members of the same class.
However, with Method B you cannot assign the same object directly to this
.
Or is there another way to do this?