在修复一个项目中的bug时发现有趣的问题
IList<int> a =new List<int>();
var b = new int[2];
b[0] = 1;
b[1] = 2;
a = b;
a.Clear();
Run Code Online (Sandbox Code Playgroud)
此代码在a.Clear()上抛出异常; 我知道如何解决它,但我没有明确得到导致此NotSupported异常的所有步骤.为什么编译器没有抛出编译时错误?
这是我的问题:
[HttpPost]
public ActionResult AddData(CandidateViewModel viewModel)
{
var newCandidateId = 0;
newCandidateId = this._serviceClient.AddCandidate(viewModel);
return RedirectToAction("DisplayCandidate",new {id=newCandidateId});
}
public ActionResult DisplayCandidate(int id)
{
var candidateViewModel= this._serviceClient.GetCandidate(id);
return View(candidateViewModel);
}
Run Code Online (Sandbox Code Playgroud)
填写表单后viwemodel发送到服务器.存储数据后,将流重定向到DisplayCandidate操作,它会转到那里,但页面没有刷新.我不明白为什么!请帮忙.
有增量问题.我创建了一个新对象并尝试将其设置到我的数据库中我收到了数据违规错误.表中的索引没有增加(Id = 0).Id - 在SQL表中设置为主键,StoredGeneratedPattern在EDM中设置字段"Id" 的属性设置为"Identity",因此,显然,它必须自动递增.
public void AddPhone(UserPhone phone)
{
context.AddToUserPhone(phone);
context.SaveChanges();
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么.