我如何...在MVC4中动态地向模型类添加新字段 [英] How do I...Add New Field to Model Class Dynamically in MVC4
本文介绍了我如何...在MVC4中动态地向模型类添加新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi
in have one table in my db, Table Name is Students
Column Name DataType
ID int
FieldName varchar(50)
and i insert some records in that table
below :
ID FieldName
1 ID
2 FirstName
3 LastName
4 Standard
5 Section
6 School
7 City
I insert 7 records
My Model Class
public class Studentdetails
{
public int UID { set; get; }
[Required]
public string ID { set; get; }
[Required]
public string FirstName { set; get; }
[Required]
public string LastName { set; get; }
[Required]
public string Standard { set; get; }
[Required]
public string Section { set; get; }
[Required]
public string School { set; get; }
[Required]
public string City { set; get; }
}
My Requirement is When I add New New Record in Students table
that will added dynamically in to Studentdetails class as new property
Ex Suppose i add new record like phno then my table come like this
ID FieldName
1 ID
2 FirstName
3 LastName
4 Standard
5 Section
6 School
7 City
8 Phno
i want my model automatically change in to below like this
public class Studentdetails
{
public int UID { set; get; }
[Required]
public string ID { set; get; }
[Required]
public string FirstName { set; get; }
[Required]
public string LastName { set; get; }
[Required]
public string Standard { set; get; }
[Required]
public string Section { set; get; }
[Required]
public string School { set; get; }
[Required]
public string City { set; get; }
public string Phno { set; get; }
}
anybody know pls answer this.........
推荐答案
不确定是否有自动方式,但你可以通过从EDMX文件更新模型来实现。
参考
数据库先发展/改变最数据库 [ ^ ]
更改数据库字段和更新管理ADO-EN tity-model-edmx [ ^ ]
Not sure whether there is a way "automatic", But you can surely do it through Updating the Model from EDMX file.
Refer
database-first-development/changing-the-database[^]
changing-database-fields-and-updating-ado-entity-model-edmx[^]
这篇关于我如何...在MVC4中动态地向模型类添加新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文