Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4063208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:41:47+00:00 2026-05-20T15:41:47+00:00

I am just diving into the use of code-first with CTP5 for Entity Framework.

  • 0

I am just diving into the use of code-first with CTP5 for Entity Framework. To ease the pain of configuring the database mappings I’ve created myself a little helper class to serve as the base class for any custom mappings, but I’m unable to figure out how to make the last statement in the method work.

I am locating all public properties of type Enum and then calling the .Ignore method for every property found on the given type. The code uses Fasterflect for reflection and a little ForEach helper, but it should be fairly obvious what the code does.

internal abstract class AbstractMappingProvider<T> : IMappingProvider where T : class
{
    public EntityTypeConfiguration<T> Map { get; private set; }

    public virtual void DefineModel( ModelBuilder modelBuilder )
    {
        Map = modelBuilder.Entity<T>();

        Map.ToTable( typeof(T).Name );

        typeof(T).Properties( Flags.Public | Flags.Instance )
            .Where( p => p.PropertyType.IsEnum )
            .ForEach( p => Map.Ignore( e => p ) );
    }
}

Executing the above gives me the following error:

System.InvalidOperationException: 
The expression 'e => value(Domain.AbstractMappingProvider`1+<>c__DisplayClass3[Domain.User]).p' is not a valid property expression.
It must be of the form 'e => e.Property'.

How can I use the “p” (which is in fact a property on “e”) to make this not just compile but also work? :o)

I’m hoping someone has a clever trick to solve this. Alternatives solutions are welcome, but remember that the whole idea is to avoid having to call Map.Ignore for every enumeration property.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:41:48+00:00Added an answer on May 20, 2026 at 3:41 pm

    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<T> : IMappingProvider where T : class
    {
        public EntityTypeConfiguration<T> Map { get; private set; }
    
        public virtual void DefineModel(DbModelBuilder modelBuilder)
        {
            Map = modelBuilder.Entity<T>();
    
            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<TPropertyType>(LambdaExpression lambdaExpression)
        {
            var expression = (Expression<Func<T, TPropertyType>>) lambdaExpression;
            Map.Ignore(expression);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm diving into iOS development and I just built my first game. Since Apple
I'm just diving into WPF and find this a little odd and frustrating to
I'm just diving into the exciting world of facebook app creation, but have already
I just started diving into the world of Rails by reading the well known
I just recently started diving into Real World Haskell and the book provides some
I'm diving into iOS development and I just found out about the Static Analyzer
I just started diving into Metro Style application development and I realized that there
I'm just diving into some C++ and I decided to make a random number
I am having trouble getting my 3D model textured, I am just diving into
Greetings, people. I'm diving into Objective-C for pretty much the first time. It's kicking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.