var newThing = db.Things.SingleOrDefault(t => t.ThingName == viewModel.ThingName);
if (newThing == null)
{
newThing.ThingName.Equals(viewModel.ThingName);
}
如果上述 if 语句为真,我会收到一个
Object reference not set to an instance of an object
异常,因为 newThing 为空。是否可以初始化 NewThing 并将 newThing.ThingName 设置为 viewModel.ThingName?