Skip to content

GetProperty should return null if not found; instead it throws an exception #27791

@VAchris

Description

@VAchris

We have a disconnect between what the documents say should be happening versus what's implemented.

In the file IReadOnlyEntityType.cs when you try to get a property that does not exist it throws an InvalidOperationException whereas the expected return value is null.

Example

var entityType = MyDbContext.Set<E>().EntityType;
var property = entityType.GetProperty(invalidPropertyName); // this throws an exception

Include stack traces

System.InvalidOperationException: The property 'MyTable.invalidPropertyName' could not be found. Ensure that the property exists and has been included in the model.
   at Microsoft.EntityFrameworkCore.Metadata.IReadOnlyEntityType.GetProperty(String name)
   at Microsoft.EntityFrameworkCore.Metadata.IEntityType.GetProperty(String name)

Include provider and version information

EF Core version: 6.0.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6
Operating system: Windows 10
IDE: VS 2022

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions