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

Document TPC #4080

Merged
merged 1 commit into from
Oct 13, 2022
Merged

Document TPC #4080

merged 1 commit into from
Oct 13, 2022

Conversation

AndriySvyryd
Copy link
Member

@AndriySvyryd AndriySvyryd commented Oct 11, 2022

Fixes #3764
Fixes #3765

@AndriySvyryd AndriySvyryd requested a review from a team October 11, 2022 21:08
@AndriySvyryd AndriySvyryd force-pushed the Issue3764 branch 2 times, most recently from c4e107a to be61644 Compare October 11, 2022 21:36

In the TPT mapping pattern, all the types are mapped to individual tables. Properties that belong solely to a base type or derived type are stored in a table that maps to that type. Tables that map to derived types also store a foreign key that joins the derived table with the base table.

[!code-csharp[Main](../../../samples/core/Modeling/Inheritance/FluentAPI/TPTConfiguration.cs?name=TPTConfiguration)]

> [!TIP]
> Instead of calling `ToTable` on each entity type you can call `modelBuilder.Entity<Blog>().UseTptMappingStrategy()` on each root entity type and the table names will be generated by EF.
Copy link
Member

Choose a reason for hiding this comment

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

Should we modify the sample to use UseTptMappingStrategy by default, and show ToTable only for when you want to customize the table names?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since we say that TPT should only be used with existing databases I think that the ToTable way will be more common.

Copy link
Member

Choose a reason for hiding this comment

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

We say it should, but that doesn't necessarily means that's how users use it :) I'd still say that UseTptMappingStrategy should be the default as long it works (i.e. your tables do align with the default naming), and that ToTable should only be used when that's not the case.

But am OK if you prefer to keep as-is.

entity-framework/core/modeling/inheritance.md Outdated Show resolved Hide resolved
[!code-csharp[Main](../../../samples/core/Modeling/Inheritance/FluentAPI/TPCConfiguration.cs?name=TPCConfiguration)]

> [!TIP]
> Instead of calling `ToTable` on each entity type just calling `modelBuilder.Entity<Blog>().UseTpcMappingStrategy()` on each root entity type will generate the table names by convention.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above for TPT - I think we expect most users to use the new UseTp*MappingStrategy, rather than ToTable, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

UseTpcMappingStrategy needs to be called anyway, I don't think that removing the ToTable calls from the sample improves it.

Copy link
Member

Choose a reason for hiding this comment

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

Well it's redundant code for many uses cases - we don't have ToTable in regular, non-inheritance code samples. But anyway...

entity-framework/core/modeling/inheritance.md Outdated Show resolved Hide resolved
entity-framework/core/modeling/inheritance.md Outdated Show resolved Hide resolved
entity-framework/core/modeling/relationships.md Outdated Show resolved Hide resolved
entity-framework/core/modeling/table-splitting.md Outdated Show resolved Hide resolved
entity-framework/core/modeling/table-splitting.md Outdated Show resolved Hide resolved
@AndriySvyryd AndriySvyryd force-pushed the Issue3764 branch 2 times, most recently from 10897d0 to 83dd930 Compare October 13, 2022 00:13
Fixes #3764
Fixes #3765
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update TPT Document TPC
2 participants