一个设置EF Core 6 Identity模型如何使用时间表?

发布于 2025-02-05 07:24:27 字数 676 浏览 5 评论 0原文

EF6现在发布了使用.totable(e => e.istemporal())在配置和Fluent API中执行时间表的功能,该功能很棒,并且对我的模型中的所有表都有效。

但是,我使用的是身份模型(Aspnetuser,Aspnetrole等),并且这些表没有使用.totable语法使其使其暂时性的设置;看来我有两个关于如何使这些暂时性在EF6世界中的选择。但是我希望有一个更好的选择,并且想知道是否有人知道理想(或至少推荐)方法

选项1:手动sql语句

在迁移中,我可以做诸如migrationBuilder.sql的事情(” Alter Table aspnetuser SET(System_versioning = on(history_table = aspnetuserhistory)))。这很好,但是是手动的,似乎不是推荐的方法。

选项2:具有继承的表格创建表中的表格

在我的模型中,我可以为所有身份模型类型(公共类应用程序:IdentityUser)创建对象,然后将它们映射到同一表名称并包括(包括( e =>但这意味着创建所有只是继承但不添加任何东西以获取时间表的所有对象(希望有更好的方法)

选项3:推荐的Microsoft方法

我找不到推荐的方法来执行此操作;希望它确实具有标准 /推荐的解决方案

EF6 has now released the ability to do temporal tables within the configuration and fluent api using the .ToTable(e => e.IsTemporal()) which is great and has worked for all the tables in my model.

However I'm using Identity Model (AspNetUser, AspNetRole, etc...) and those tables don't have that setup to use the .ToTable syntax to make them temporal; it looks like I have two options on how to make those temporal in the EF6 world; but I was hoping for a better option and was wondering if anyone knows of the ideal (or at least recommended) method

Option 1: Manual SQL Statement

In a migration I can do something like migrationBuilder.Sql("ALTER TABLE AspNetUser SET(SYSTEM_VERSIONING = ON (HISTORY_TABLE = AspNetUserHistory))"). This is fine, but is manual and doesn't seem like it would be the recommended method.

Option 2: Explicit Creation of Tables with Inheritance

In my model I could create objects for all the Identity Model types (the public class ApplicationUser : IdentityUser) and then map those to the same table name and include the (e => e.IsTemporal()); but that means creating all those objects which just inherit but don't add anything just to get temporal tables (hoping there is a better way)

Option 3: Recommended Microsoft Method

I wasn't able to find a recommended method to do this; hoping that it is something that does have a standard / recommended solution

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2025-02-12 07:24:28

直接利用身份对象,

看起来我们可以直接使用Microsoft.aspnetcore.Identity名称空间来创建那些诸如this

ModelBuilder.entity.entity< IdentityRoleleclaim>()的时间表。

Utilisation of Identity Object Directly

It looks like we can use the Microsoft.AspNetCore.Identity namespace directly to create those temporal tables like this

modelBuilder.Entity<IdentityRoleClaim>().ToTable(e => e.IsTemporal());

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文