提问人:decoder 提问时间:10/21/2019 最后编辑:decoder 更新时间:10/21/2019 访问量:61
不一致的 null 赋值
Inconsistent null assignment
问:
无法为以下代码赋值 null 值
[Table("POSMachine")]
public class POSMachine
{
public int ID { get; set; }
public string POSSN { get; set; }
public int? ReceivedBy { get; set; }
public int? ReceivedFrom { get; set; }
[ForeignKey("ReceivedFrom")]
public virtual TeamMember ReceivedFromMember { get; set; }
[ForeignKey("ReceivedBy")]
public virtual TeamMember ReceivedByMember { get; set; }
}
private void LoadMachineObj(POSMachine machine)
{
var receivebymember = _context.TeamMembers.Where(m => m.IsActive == true && m.ID == receivebyid).FirstOrDefault();
machine.ReceivedByMember = receivebymember;
var receivefrommember = _context.TeamMembers.Where(m => m.IsActive == true && m.ID == 1).FirstOrDefault();
machine.ReceivedFromMember = receivefrommember;
}
//calling method:
var machine = _context.POSMachines.Where(v => v.ID == id).FirstOrDefault();
LoadMachineObj(machine);
_context.Entry(machine).State = EntityState.Modified;
_context.SaveChanges();
如果变量为 null,则保存上一个对象引用,类似于 。但有时会变成空。如果为 null,为什么有时变为 null,有时不变为 null。我的实体对象定义是否正确?receivefrommember
machine.ReceivedFromMember
System.Data.Entity.DynamicProxies.TeamMember_98A56E4F3F20CCE075A377A6C5A2A9E1C6BFE2A0F00566726C986B9313FBB82C
receivefrommember
machine.ReceivedFromMember
答: 暂无答案
评论
ReceivedFromMember
是虚拟财产,也许它在某个地方被覆盖了?