我实际上只是想在我的设计模型中将一些项目附加到ICollection中。
newItem.EmployeeIds有一个完全正常工作的ID列表。
例如:
public class Employee
{
public Employee()
{
this.Notes = new List<Note>();
this.DirectReports = new List<Employee>();
}
public int Id { get; set; }
public ICollection<Employee> DirectReports { get; set; }
public ICollection<Note> Notes { get; set; }
}
我试过这个:
public IEnumerable<EmployeeList> ConfigureDirectReports(EmployeeDirectReports newItem)
{
var fetchedObject = ds.Employees.Find(newItem.Id);
System.Diagnostics.Debug.WriteLine(fetchedObject.DirectReports.Count());
if (fetchedObject.IdentityUserId == User.Identity.Name)
{
ds.Entry(fetchedObject);
foreach (var item in newItem.EmployeeIds) {
fetchedObject.DirectReports.Add(ds.Employees.Find(item));
}
ds.SaveChanges();
return null;
}
return null;
}
我正在尝试在DirectReports
中保存一些Employee对象。