如何在exits datatbase列中的指定位置向Entity Framework模型类添加新属性。 [英] how to add new attribute to an Entity Framework model class with specified position in exits datatbase column.
问题描述
我首先使用实体框架代码来创建数据库。
i希望在[Name]列之后向现有表添加新字段(描述)。
我的步骤:
1.存在表(博客)看起来像:
[ID,Name,Url]
2.我想在[Name]栏之后将[Description]添加到Blog表中,它应该是:
[ID,Name, 描述 ,网址]
3.博客的实体框架模型类:
I'm using entity framework code first to created database.
i want to add a new field(description) to an exist table after it's [Name] column.
My steps:
1. Exist Table ( Blog ) looks like:
[ID, Name, Url]
2. I want to add [Description] to Blog table after [Name] column, it should to be:
[ID, Name, Description, Url]
3. Entity framework model class of Blog:
public partial class Blog
{
[Key]
public int ID {get; set;}
public string Name {get; set;}
public string Url {get; set;}
}
4.我添加新的博客模型中的属性[描述]:
4. i add new attribute [Description] in Blog model:
<pre lang="c#">
public partial class Blog
{
[Key]
public int ID {get; set;}
public string Name {get; set;}
// new attribute, which i want to add this column in table after Name
public string Description {get; set;}
public string Url {get; set;}
}
5.添加迁移:
添加迁移AddDescriptionForBlog
6 。更新数据库:
更新数据库
7.查看表格,在最后一栏放置[描述]字段。
[ID,Name,Url, 说明 ]
我的问题:
如何将[描述]放在表格中名称列之后的文件中?
5. add migration:
Add-Migration AddDescriptionForBlog
6. update database:
Update-Database
7. look at table, it place [Description] field at last column.
[ID, Name, Url, Description]
My question:
how can i place [Description] in filed after Name column in the table?
推荐答案
这篇关于如何在exits datatbase列中的指定位置向Entity Framework模型类添加新属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!