0

All my entities inherit from a base class that contains a private RowVersion property. I am trying to configure a custom convention and I receive the following error:

"The property 'RowVersion' is not a declared property on type 'CustomerResponse'. Verify that the property has not been explicitly excluded from the model by using the Ignore method or NotMappedAttribute data annotation. Make sure that it is a valid primitive property."

Here is my convention:

public sealed class RowVersionConvention : Convention
{
    public RowVersionConvention()
    {
        Types().Having(t => t.BaseType.GetProperty("RowVersion", BindingFlags.SetProperty | BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance))
            .Configure((config, property) =>
            {
                config.Property(property).IsRowVersion();
            });
    }
}

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {

        modelBuilder.Conventions.Add(new RowVersionConvention());
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
    }

Any help would be greatly appreciated!

Marco
  • 2,453
  • 3
  • 25
  • 35
  • the problem is the visibility. You can't use a `private` property. In such case how could EF materialize the property if it can't acces it ? – tschmit007 May 21 '15 at 14:34
  • it sure does work if i put the private property within the class itself and NOT a base class. http://romiller.com/2013/01/23/ef6-code-first-mapping-all-private-properties-using-custom-conventions/ – Marco May 21 '15 at 14:36
  • it seems you are right, but it is not trivial : http://stackoverflow.com/questions/13807406/entity-framework-many-to-many-through-containing-object/13810766#13810766, but imho it wouldn't help in your case. – tschmit007 May 21 '15 at 14:38
  • from here http://stackoverflow.com/questions/7619955/mapping-private-property-entity-framework-code-first you can try to have a public property with private setters `public RowVersion {private get; private set;}` – tschmit007 May 21 '15 at 14:41
  • i am trying to keep my model clean of infrastructure details so i may just end up wiring it up per class and not put it up in a super type. – Marco May 21 '15 at 14:43
  • Not sure, but maybe [`MapInheritedProperties`](https://msdn.microsoft.com/en-us/data/jj591617.aspx#2.6) would help? – jjj May 21 '15 at 23:28

0 Answers0