In my EF code, I use classes based on the EntityTypeConfiguration<T> class to do the configuration.
In these classes, I have helper methods to help with the configuration. For example, I have the following code:
protected void MapGuidColumn(Expression<Func<T, Guid>> selector, string columnName, bool isRequired, bool isIdentity) { PrimitivePropertyConfiguration configuration = null; configuration = this.Property(selector); configuration.HasColumnName(columnName); if (isRequired == true) { configuration.IsRequired(); } else { configuration.IsOptional(); } if (isIdentity == true) { configuration.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity); } return; }
I call this method using an operator like the following:
MapGuidColumn(e => e.ID, "ID", true, true);
In the MapGuidColumn method MapGuidColumn expression that is actually received is e => Convert(e).ID , not e => e.ID EF seems to have problems with this expression in the expression configuration = this.Property(selector); . It fails with the following exception message:
System.InvalidOperationException: The expression 'e => Convert (e) .ID' is not a valid property expression. The expression should represent the property: C #: 't => t.MyProperty' VB.Net: 'Function (t) t.MyProperty'. Use the dotted paths for nested properties: C #: 't => t.MyProperty.MyProperty' VB.Net: 'Function (t) t.MyProperty.MyProperty'.
I used this method in the past, but I never looked at the expression obtained by helper methods. However, this is the first time that I have encountered this problem.
Can someone point me in the direction of what could be happening here? I can provide more code if necessary (I'm just not sure what to provide at this point).
source share