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?
一个重要的注意的是,这当然不会添加新的东西到DB。从这个问题来看,这还不是很清楚。 – svick
@svick,你是绝对rigth – Satpal