我正在尝试将列表保存到数据库,但是,它没有任何作用。
这是我的模特:
private IList<int> _chatIDs;
public IList<int> ChatIDs
{
get { return _chatIDs ?? (_chatIDs = new List<int>()); }
set { _chatIDs = value; }
}
这是最省钱的部分:
MyDbContext myDbContext = new MyDbContext();
var game = myDbContext.Events.Find(e.ID);
var newList = game.ChatIDs;
newList.Add(e.ChatID);
game.ChatIDs = newList;
myDbContext.SaveChanges();
我的错误在哪里?
答案 0 :(得分:0)
数据库架构概述:
然后在模型中为这些外键关系创建集合,如下所示(很抱歉,我花时间编写示例代码,我只是从我当前项目之一的生成实体中获取了代码):< / p>
public partial class SecurityUser
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public SecurityUser()
{
this.SW_Mobile_Pick_Assignment = new HashSet<SW_Mobile_Pick_Assignment>();
this.SW_Mobile_Session = new HashSet<SW_Mobile_Session>();
}
public int SecurityUserId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Login { get; set; }
public string Passwrd { get; set; }
public string Email { get; set; }
public bool Enable { get; set; }
public string FileMakerId { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public Nullable<bool> IsAccountManager { get; set; }
public Nullable<bool> IsHandHeldAccount { get; set; }
public Nullable<int> HandheldPin { get; set; }
public string Last5SSN { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SW_Mobile_Session> SW_Mobile_Session { get; set; }
}