This uses the standard . NET reflection libraries but I'm sure you can convert it to fasterflect if you like. I've added an Ignore method to the AbstractMappingProvider so that we can use MakeGenericMethod() to resolve the generic type for the property at runtime in order to cast the Lambda we have at that point to the correct Expression type.
There could well be a better/faster/easier way to do this.
This uses the standard . NET reflection libraries but I'm sure you can convert it to fasterflect if you like. I've added an Ignore method to the AbstractMappingProvider so that we can use MakeGenericMethod() to resolve the generic type for the property at runtime in order to cast the Lambda we have at that point to the correct Expression type.
There could well be a better/faster/easier way to do this. As a side note, I'm fairly sure that in that the code first Release Candidate (part of the Entity Framework 4.1 release candidate), enums are already ignored by default when mapping by convention. Internal abstract class AbstractMappingProvider : IMappingProvider where T : class { public EntityTypeConfiguration Map { get; private set; } public virtual void DefineModel(DbModelBuilder modelBuilder) { Map = modelBuilder.Entity(); Map.
ToTable(typeof(T). Name); var properties = typeof(T). GetProperties(BindingFlags.
Public | BindingFlags. Instance). Where(p => p.PropertyType.
IsEnum); var parameterExpression = Expression. Parameter(typeof(T), "e"); foreach (var propertyInfo in properties) { // Build up the expression var propertyExpression = Expression. Property(parameterExpression, propertyInfo); var funcType = typeof (Func).
MakeGenericType(typeof (T), propertyInfo. PropertyType); var ignoreExpression = Expression. Lambda(funcType, propertyExpression, new {parameterExpression}); // Call the generic Ignore method on this class, passing in the expression var ignoreMethod = this.GetType().
GetMethod("Ignore"); var genericIgnoreMethod = ignoreMethod. MakeGenericMethod(propertyInfo. PropertyType); genericIgnoreMethod.
Invoke(this, new object{ignoreExpression}); } } public void Ignore(LambdaExpression lambdaExpression) { var expression = (Expression>) lambdaExpression; Map. Ignore(expression); } }.
Wow that did exactly what I needed. In fact, your side note might have sufficed (can't believe I just assumed it would break on seeing an enum property), but I'm very happy with also seeing what I should have written :) – Morten Mertner Mar 18 at 20:25.
The problems is that P is a PropertyInfo object. That class has metadata about the property but knows nothing about values assigned to the property on various objects. You will have to manually create an Expression object to pass in to the Ignore method based by leveraging the property name that you can get from P.
– Morten Mertner Mar 13 at 5:55 @Morten, sorry I don't know a whole lot about working with Expressions... just enough to know that's what you need here :) – Robert Levy Mar 13 at 5:59 Buggers, as it's not exactly my strong side either. I can see that it wants an Expression> but how to create that from my ingredients... :) Hopefully someone else can shed more light on this. – Morten Mertner Mar 13 at 6:17.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.