Efcore: Fluent API property expressions does not support chained member access

Created on 11 Feb 2015  路  5Comments  路  Source: dotnet/efcore

With EF7 the mapping modelBuilder.Entity<Entity>().Property( x => x.Irrelevant.Property1 ), throws an exception:

System.ArgumentException: The expression 'x => x.Irrelevant.Property1 ' is not a valid property expression. The expression should represent a property access: 't => t.MyProperty'.

This is more limited than EF6. In EF6 it is valid to chain member access to map a property on a nested object. That is a mapping such as the following was valid:

``` c#
...
Property( x => x.Irrelevant.Property1 )

That would work so long as you set `Irrelevant` in the entity's getter:

``` c#
public IrrelevantType Irrelevant
{
    get
    {
        return _irr ?? ( _irr = new IrrelevantType () );
    }
    set
    {
        return irr = value;
    }

I am not able to determine if this is something that is not implemented yet, an intentional change, or a bug.

EF: 7.0.0-beta4-12175

closed-not-needed

Most helpful comment

Discussed in triage and agreed that we should not do this because the semantics would not be clear, specially if done before any OwnsXxx call has been made.

All 5 comments

This is because we don't yet support nested objects (or "complex types" as we typically call them). Here is the work item tracking it https://github.com/aspnet/EntityFramework/issues/246.

Thank you! It is good to know the right way to refer to them :thumbsup:

@rowanmiller Is there a solution to implement complex type mapping already?

@douglasoliveirabh we added support for owned types in 2.0, which provides a superset of the capabilities of complex types.

However owned types are never mapped by convention. I.e. in order for a type to become an owned type you have to explicitly address it with the OwnsOne method.

Given that I am not sure it would be viable to enable chained member access in the Property<T> method.

Reopening so that we can discuss it.

Discussed in triage and agreed that we should not do this because the semantics would not be clear, specially if done before any OwnsXxx call has been made.

Was this page helpful?
0 / 5 - 0 ratings