Is it possible to map following POCO class with EF 4.0?
public class MyClass
{
private string _myData;
public MyClass()
{ }
public MyClass(string myData)
{
_myData = myData;
}
public string MyData
{
get
{
return _myData;
}
}
}
In NHibernate I think it is possible when I use Access attribute in mapping like:
<class name="MyClass" table="MyTable">
<property name="MyData" access="field.camelcase-underscore" column="MyCol" type="string" length="50" />
</class>
I wonder if there is some Access equivalent in EF 4.0? Currently I'm able to map the class only if I add protected setter to the MyData property:
public string MyData
{
get
{
return _myData;
}
protected set
{
_myData = value;
}
}
It works but for legacy classes it means update all properties which don't have setter.
Edit:
I have updated the last code example because it also doesn't work with private setter. Setter has to be at least protected. If the setter is private or doesn't exists following exception is thrown:
See Question&Answers more detail:osSystem.InvalidOperationException: Mapping and metadata information could not be found for EntityType 'MyNamespace.MyClass'.