我有 2 个类,其中一个类嵌套在另一个类中,就像这样
public class Account {
public int id {get; set;}
public string Name {get; set;}
public Input AccountEntry {get; set;}
}
public class AccountEntry {
public int id {get; set;}
public date date {get; set;}
public string description {get; set;}
public decimal hour {get; set;}
}
并像这样使用 InMemory 数据库:
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseInMemoryDatabase("AccountDB");
}
它添加了这样的记录:
public void AddTimesheet(Account account)
{
_context.Accouunts.Add(account);
_context.SaveChanges();
}
并像这样查询:
public IList<Account> GetAllAccounts()
{
return _context.Accounts.ToList();
}
首次发帖时保存,记录可以在同一个请求中正确查询。当发布另一个输入时,所有先前记录的嵌套
AccountEntry
都是 null
(Account.AccountEntry = null
),但像名称这样的直接属性可以保留。如果是范围问题,worker 字段也应该丢失。
为什么只有嵌套对象丢失了?
有什么办法可以解决吗