Trying to implement a generic repository based on an article by Chris Pratt that uses object as the Id (PK).
All is good, until I tried to .Map()one of these objects with ExpressMapper.
More code below. But essentially, when I try and do this:
var dataModel = postedModel.Map(new ExampleDataModel());
It gives me:
No parameterless constructor defined for this object.
When I change the Id property of ExampleDataModel to a string or int it works fine.
I've googled around. I don't see anything obvious, but I am a bit out of my depth. I'd like to know:
What is causing this?
Can I work round it somehow?
I'd like to continue using the object PK and ExpressMapper if possible because they're both suiting my project just fine.
public interface IDataModel
{
object Id { get; }
}
public interface IDataModel<PKT> : IDataModel
{
new PKT Id { get; set; }
}
public abstract class DataModel<PKT> : IDataModel<PKT>
{
public PKT Id { get; set; }
object IDataModel.Id
{
get { return this.Id; }
}
}
public class ExampleDataModel :
DataModel<string>,
IDataModel<string>
{
public virtual string SomeProperty{ get; set; }
// etc.
}