Fluent API property expressions does not support chained member access
See original GitHub issueWith 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:
- Created 9 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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.