I have a \'naïve\' question.
With the following sample code:
public class ThisClass
{
public int ThisClassID { get; set; }
public string ThisValu
You should take a look at AutoMapper, and your code could look as follows:
// Somewhere in your application/service initialization class and in some method...
Mapper.CreateMap();
public class ThisClass
{
public int ThisClassID { get; set; }
public string ThisValue { get; set;}
public ThisClass()
{
}
public ThisClass(int thisClassID)
{
using (MyContext dbContext = new MyContext())
{
Mapper.Map(dbContext.CaseNotes.Find(thisClassID), this);
}
}
}
BTW it sounds like a bad idea. I wouldn't populate a domain object inside its own constructor.
This is a good responsibility for the repository.