Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key property with private set isn't being discovered #26

Open
Crimp opened this issue Jan 19, 2022 · 1 comment
Open

Key property with private set isn't being discovered #26

Crimp opened this issue Jan 19, 2022 · 1 comment
Labels
question Further information is requested

Comments

@Crimp
Copy link

Crimp commented Jan 19, 2022

When we have the private set for the Key property. The EF works well with it Read-only properties. And we have all BO with private/proteced Key set.

Reproduce steps

The next classes set :

    public class TestUser {
        public int ID { get; protected set; }
        public string FullName { get; set; }

        public virtual IList<TestRole> Roles { get; set; }
    }

    public class TestRole {
        public int ID { get; protected  set; }
        public string FullName { get; set; }

        public virtual IList<TestUser> Users { get; set; }
    }

Will work properly when we register both types and their keys manually:

ODataConventionModelBuilder builder = ...
Type typeToRegister = typeof(TestUser);
builder.AddEntityType(typeToRegister ).HasKey(typeToRegister.GetProperty("Id"))

typeToRegister = typeof(TestRole);
builder.AddEntityType(typeToRegister ).HasKey(typeToRegister.GetProperty("Id"))

But it's not convenient to register all types from types hierarchy manually. In general we want to register only top hierarchy objects and provide registration of other types to the system.

And when we register only one type from that example:

Type typeToRegister = typeof(TestUser);
builder.AddEntityType(typeToRegister ).HasKey(typeToRegister.GetProperty("Id"))

The TestRole type is resolved as Complex type and not the Entity type, because it can not discover it's Key property.

Expected result

The Key property with private/protected set is discovered and type is considered as the Entity type.

Actual result

The Model builder skip all properties with private/protected set.

Additional detail

The Microsoft.OData.ModelBuilder.ConventionsHelpers.GetAllProperties method doesn't return property with private set. After that the Microsoft.OData.ModelBuilder.EntityKeyConvention.GetKeyProperty cannot discover key property.

@xuzhg xuzhg added the question Further information is requested label Jun 9, 2022
@SergioComputerx
Copy link

Same bug here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants