저는 최신 Asp.Net MVC 버전을 사용하고 있습니다.Asp.Net MVC 3 - 엔티티에 Linq - Null과 PK가 db에 삽입되지 않습니다. null을 원하지 않습니다.)
내 컨트롤러의 내 POST (작업 만들기)에 충돌이 발생하는 이유가 있습니다. 엔티티 집합에 추가 할 수없는 것 같습니다. 나는이 것을
, 엔티티 참조
1) 내 EntityModel (* .edmx 파일)
2) 컨트롤러 :
private db.DataContainer _db = new db.DataContainer();
3) 내 방법을 (내가 해요) PK로 GUID 사용 : 다음
[HttpPost]
public ActionResult Create(Client client)
{
try
{
client.Id = Guid.NewGuid();
/* method 2
Client cl = new Client();
cl.Id = Guid.NewGuid();
cl.email = client.email;
cl.Adres = client.Adres;
cl.companyName = client.companyName;
cl.fax = client.fax;
cl.phone = client.phone;
*/
// client.Id = Guid.NewGuid();
_db.ClientSet.AddObject(client);
_db.SaveChanges();
return RedirectToAction("Index");
}
catch (Exception ex)
{
var ex_message = ex.Message;
var ex_data = ex.Data;
var ex_ix = ex.InnerException;
return View();
}
}
4) 내의 InnerException입니다 :
나는 chaned : 6,[System.Data.SqlClient.SqlException] = {"Cannot insert the value NULL into column 'Id', table 'lst.dbo.ClientSet'; column does not allow nulls. INSERT fails.\r\nThe statement has been terminated."}
모두
StoreGeneratedPattern을 None으로 변경합니다. – LukLed