Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I exclude Enum properties with EF4/CTP5 fluent mappings in a generic fashion?
    primarykey
    data
    text
    <p>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.</p> <p>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.</p> <pre><code>internal abstract class AbstractMappingProvider&lt;T&gt; : IMappingProvider where T : class { public EntityTypeConfiguration&lt;T&gt; Map { get; private set; } public virtual void DefineModel( ModelBuilder modelBuilder ) { Map = modelBuilder.Entity&lt;T&gt;(); Map.ToTable( typeof(T).Name ); typeof(T).Properties( Flags.Public | Flags.Instance ) .Where( p =&gt; p.PropertyType.IsEnum ) .ForEach( p =&gt; Map.Ignore( e =&gt; p ) ); } } </code></pre> <p>Executing the above gives me the following error:</p> <pre><code>System.InvalidOperationException: The expression 'e =&gt; value(Domain.AbstractMappingProvider`1+&lt;&gt;c__DisplayClass3[Domain.User]).p' is not a valid property expression. It must be of the form 'e =&gt; e.Property'. </code></pre> <p>How can I use the "p" (which is in fact a property on "e") to make this not just compile but also work? :o) </p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload