1

如何在 EF 中更新 ICollection 属性?

我收到此错误消息;

“不能将类型'int'隐式转换为' System.Collections.Generic.ICollection<MySolution.Domain.UserProfile>'”

我的实体:

public class Department
{
    public virtual int Id { get; set; }
    public virtual string DepartmentTitle { get; set; }
    public virtual ICollection<UserProfile> UserProfiles { get; set; }

}

public class UserProfile
{
    public virtual int UserId { get; set; }
    public virtual string UserName { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }

}

代码;

    var userProfile = _db.UserProfiles.Single(d => d.UserName == "SomeUserName");

    var department = _db.Departments.Single(d => d.Id == variableDepartmentID);
    department.UserProfiles = uProfile.UserId;
    _db.UpdateDepartment(department);
    _db.Save();
4

0 回答 0