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

Add GetDbSets and fix error details of incorrect Entity type full name #23946

Merged
merged 28 commits into from
Jan 28, 2021

Conversation

Ali-YousefiTelori
Copy link
Contributor

@Ali-YousefiTelori Ali-YousefiTelori commented Jan 23, 2021

  • Fix the error detail when you try to add or update with an incorrect Entity type, In before we had the message of "Cannot create a DbSet for '{typeName}' because this type is not included in the model for the context." now we have full details of the message that is like "Cannot create a DbSet for 'EFCoreCheck.MySpace.User' because this type is not included in the model for the context.
    Your types:
    EFCoreCheckSpace.User,
    MyNewNameSpace.TransactionInfo"

Ali-YousefiTelori and others added 7 commits January 13, 2021 18:42
Bumps Microsoft.AspNetCore.OData from 7.5.2 to 7.5.4.

Signed-off-by: dependabot[bot] <support@github.com>
"Cannot create a DbSet for '{typeName}' because this type is not included in the model for the context"
for Developers to find duplicate types with different namespaces
When you have duplicate entity with same name you will get this error with namespaces and your entity types you can find the problem easier
…ft.Azure.Cosmos-3.16.0

Bump Microsoft.Azure.Cosmos from 3.15.1 to 3.16.0
…ft.AspNetCore.OData-7.5.4

Bump Microsoft.AspNetCore.OData from 7.5.2 to 7.5.4
@dnfadmin
Copy link

dnfadmin commented Jan 23, 2021

CLA assistant check
All CLA requirements met.

@ajcvickers
Copy link
Member

@Ali-YousefiTelori How does knowing the types that are in the model help people resolve this error?

@ajcvickers ajcvickers self-assigned this Jan 25, 2021
@Ali-YousefiTelori
Copy link
Contributor Author

@ajcvickers In the past week, We got a problem with our project that got a developer one day time to find the problem and fix it.
What was the problem?

We had two entities with the same name but different namespace:

1.TransactionInfo in SQL Relational example: SqlNamesapce.TransactionInfo
2.TransactionInfo in NoSql Mongo example : MogoNamespace.TransactionInfo

With a developer mistake who use SqlNamesapce.TransactionInfo in DBSets of SqlDbContext but he sent MogoNamespace.TransactionInfo to context.Set... to get DbSet and add data to the database.
So we get that error. We didn't know we used different wrong TransactionInfo because the error does not show us the namespace of TransactionInfo.

DbSet<TInfo> table = context.Set<TInfo>();
await table.AddAsync(info);
await context.SaveChangeAsync();

I think these codes I pushed, will help the developer to know the Namespace of entities when they are setting the wrong type of context.Set and they will find the bug faster.

…ic types better

and use GroupBy ShortName to to remove dupplicate type names
/// <returns>
/// the name with different namespace found
/// </returns>
internal string FindSameTypeNameWithDifferentNamespace(Type type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to Microsoft.EntityFrameworkCore.Metadata.Internal.EntityTypeExtensions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and moved

Ali-YousefiTelori and others added 2 commits January 28, 2021 09:41
Co-authored-by: Andriy Svyryd <AndriySvyryd@users.noreply.github.com>
…orkCore.Metadata.Internal.EntityTypeExtensions
@AndriySvyryd AndriySvyryd merged commit ee09fa7 into dotnet:main Jan 28, 2021
@AndriySvyryd
Copy link
Member

Thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants