I work for 3 days in Google and cannot find a useful answer, I hope someone can help me.
I start with this EXCELLENT tutorial:
http://www.asp.net/web-forms/tutorials/data-access/model-binding/retrieving-data
I am trying to expand this project so that the "Academic Year" becomes a search for another table in the database, and not an enumeration. I am surprised how hard it is to find an example illustrating this using .net 4.5, VS 2013, EF 6 and dynamic fields.
So here is what I did:
1) Added a new table called "Years" in the database (YearID tinyint PK, YearName varchar). This table is entered with possible values.
2) Renamed the field “Students from year to year” for consistency, I changed it to tinyint, created a relationship between Students.YearID and Years.YearID
3) Modified SchoolContext to include a new table:
public DbSet<Year> Years { get; set; }
4) The Year class is added as follows:
public class Year
{
public byte YearID { get; set; }
public string YearName { get; set; }
public virtual ICollection<Student> Students { get; set; }
}
5) Removed the study material from the Student class and replaced these lines:
public byte YearID { get; set; }
public virtual Year Year { get; set; }
6) Changed the field in the form to show the recently associated YearID:
<asp:DynamicField DataField="YearID" />
(Finally) problem: YearID shows as a text field, not a drop-down list, and I cannot figure out how to fix this. It worked fine when it was an enumeration, but was not as good as a search. When it was defined as an enumeration, it had this annotation:
[EnumDataType(typeof(AcademicYear)), Display(Name = "Academic Year")]
public AcademicYear Year { get; set; }
Is there a similar annotation needed to tell the dynamic control the data from the Years table? As far as I know, all this is very mysterious and undocumented.
- , , , DataField Dymanic "Year", "YearID". , "System.Data.Entity.DynamicProxies.Year_9D4E99.........".
, ForeignKey_Edit.ascx , .
, - .