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.........
ananth ganapathyPosted Feb 17, 2014, 6:52 AM
Thanks For Ur Reply,Actually I am trying to create Dynamic web form with respected to user field selection.
(ie) Consider Student table having 5 fields like name,rollno,standard,section and school..
we also create model class with respected to table fields.suppose a user need only 3 fileds like name,standard and section.
then the view should contains these three fiellds and need also validation.and another cases a user need five fields means that view contains five fields with respect to name,rollno,standard,section and school..
another scenario if we add new field in student like city then automatically model class will be updated..
is it possible to create in mvc 4..
u have any sample source related to my quries pls send that...
Thank You
Nimit JoshiPosted Feb 17, 2014, 6:02 AM
Refer: Code First Migration
Well if it is done by the ADO.NET Entity Data Model then the model is generated automatically and the properties are added automatically and after updating the database if you want that the model is to be changed then you have to update it by right click on your table diagram in the Model (Generated by ADO.NET Entity Data Model) and select Update Database. Now you can select that particular table in which the new field is added.
If you have any further query then let me know..