question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fluent API property expressions does not support chained member access

See original GitHub issue

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:

...
Property( x => x.Irrelevant.Property1 )

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

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

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
ajcvickerscommented, Aug 18, 2017

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.

1reaction
divegacommented, Aug 18, 2017

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core modelbuilder not a valid expression fluent api
The expression should represent a simple property access: 't => t.MyProperty'. This is an image of the class diagram classDiagram. and the code...
Read more >
Configure Property Mappings using Fluent API in EF Code- ...
The Fluent API can be used to configure properties of an entity to map it with a db column. Using Fluent API, you...
Read more >
How to use fluent interfaces and method chaining in C# | ...
To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don't...
Read more >
Fluent API - Configuring and Mapping Properties and Types
The code first fluent API is most commonly accessed by overriding the ... In the following example, the Name property should be no...
Read more >
Property Configuration In Entity Framework Core
You can configure entity properties via the Entity Framework Core Fluent API. ... These options are available as methods that can be chained...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found