Reputation: 293
I have a problem with one of my DbContext properties using Entity Framework database first. Basically, I have about 25 tables in my database, which I added to the edmx. Then, the edmx generated DbSets in my DbContext for every single table. My problem though is that one of those properties is set to internal and all the rest are set to public. Since it's set to internal, I can't use it in another assembly and it is also not initialized because EF only initializes public properties.
I've been hacking at this for days now and can't wrap my mind around it. Why is one table set to internal and all the others set to public? They have the same properties, I made sure that its access level is set to Public in the designer, its relationships are set properly - I see nothing different between this table and another table. Its children are also set properly.
I tried switching the access level from Public to Internal, generating the code again, and then switching it back to Public but no luck. I tried changing the name, same issue. Deleting and re-adding the table is a bit tricky because it has a lot of relationships and dependencies - I'd have to delete a bunch of tables at the same time and re-add them, otherwise EF complains. I'd prefer not to have to do that.
Any help is greatly appreciated - I'm going nuts here.
Thanks.
Upvotes: 2
Views: 1555
Reputation: 86882
In the EDMX you can set the Setter and Getter to Public, Private, Protected or Internal for any of the Properties or Navigation Properties. From your model browser you can select the entity and any of it properties then in the property window you will have the options to set the type of Getter and Setter. See image below.
This will translate appropriately using the Model.TT and Context.TT files provided by Visual Studio.
If you wanted to make the change via XML then you need to add the appropriate a:GetterAccess="" or a:SetterAccess="" attributes to the properties in the CSDL
<Property Name="Id" Type="Guid" Nullable="false" a:GetterAccess="Internal" />
Upvotes: 3