我在模型中创建了一个list属性,如此
public virtual List<String> listOfDays { get; set; }
然后我转换并将其存储在列表中,如下所示:
for (int i = 0; i < 30 i++)
{
var enrollment = new Enrollment();
enrollment.StudentID = id;
enrollment.listOfDays = searchString.ToList();
db.Enrollments.Add(enrollment);
db.SaveChanges();
}
我在这里放了一个断点...... enrollment.listOfDays = searchString.ToList();
......一切都很好。我看到转换已执行,我可以看到listOfDays中的值。
所以我想我会在我的数据库中找到一个名为listOfDays的列,因为我先做代码,但属性不存在。
然后我想我会尝试这样访问它......
var classdays = from e in db.Enrollments where e.StudentID == id select e.listOfDays;
var days = classdays.ToList();
//here I get an error message about this not being supported in Linq.
问题:
感谢您的帮助。
感谢Decker:http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx
以下是它的工作原理:
在此处使用表单集合...
在[HttpPost]中......
private void Update(FormCollection formCollection,int id)
for(int sc = 0; sc&lt; theSelectedCourses.Count(); sc ++) { var enrollment = new Enrollment(); enrollment.CourseID = Convert.ToInt32(theSelectedCourses [sc]); enrollment.StudentID = id; enrollment.listOfDays = formCollection [“searchString”]; //将其绑定为字符串而不是列表或数组。
然后在[HttpGet] ......
private void PopulateAssignedenrolledData(Student student,int id) {
var dayList =来自db.Enrollments中的e,其中e.StudentID == id选择e;
var days = dayList.ToList(); if(days.Count&gt; 0) { string dl = days.FirstOrDefault()。listOfDays; string [] listofdays = dl.Split(','); ViewBag.classDay = listofdays.ToList(); }
答案 0 :(得分:0)
感谢Decker:http://forums.asp.net/members/Decker%20Dong%20-%20MSFT.aspx
以下是它的工作原理:
在此处使用表单集合...
在[HttpPost]中......
private void Update(FormCollection formCollection,int id)
for(int sc = 0; sc&lt; theSelectedCourses.Count(); sc ++) { var enrollment = new Enrollment(); enrollment.CourseID = Convert.ToInt32(theSelectedCourses [sc]); enrollment.StudentID = id; enrollment.listOfDays = formCollection [“searchString”]; //将其绑定为字符串而不是列表或数组。
然后在[HttpGet] ......
private void PopulateAssignedenrolledData(Student student,int id) {
var dayList =来自db.Enrollments中的e,其中e.StudentID == id选择e;
var days = dayList.ToList(); if(days.Count&gt; 0) { string dl = days.FirstOrDefault()。listOfDays; string [] listofdays = dl.Split(','); ViewBag.classDay = listofdays.ToList(); }