排除要迁移的属性 [英] Exclude properties for migrations

查看:50
本文介绍了排除要迁移的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型上具有属性,我不想在迁移后在中生成字段.

I have properties on my model that I don't want to generate fields in the tables after a migration.

是否可以排除 properties 用于Entity Framework Core迁移?

Is it possible to exclude properties for Entity Framework Core migrations?

在我的 DbContext 上是否有模型的属性或某些Fluent API方法?

Is there an attribute for the model or some Fluent API method on my DbContext for this?

推荐答案

您应该能够在属性上方将 [NotMapped] 指定为数据注释.

You should be able to specify [NotMapped] as a data annotation above the property.

例如如果您希望模型中包含 FirstName LastName FullName ,则可以执行以下操作:

E.g. if you wanted to have FullName in your model which consisted of FirstName and LastName you would do:

public string FirstName { get; set; }
public string LastName { get; set; }

[NotMapped]
public string FullName { get;set };

这篇关于排除要迁移的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆