我如何在域 class 中创建 属性 而在 运行 迁移时不会添加到 table 中

How can I create Property in domain class that won't be added in table when I run migration

我想在我的域 class 中使用 Confirmpassword 属性 来检查用户是否输入了正确的密码,但我想当我 运行 迁移时它也会在 table。我如何添加这个 属性 而不将它添加到域 class 中我的 table?

我的意见是你不应该在你的域 class 中添加这个 属性。您应该使用 View Model 来保存所有额外信息并执行检查。尝试了解有关 mvc 中的视图模型的更多信息。

供日后参考;您始终可以通过添加 the NotMappedAttribute:

来排除域 class 中的 属性 成为 table 列
public class Foo
{
    public int ID { get; set; }
    public string Name { get; set; }

    [NotMapped]
    public int SomeProperty { get; set; }
}