ho semplificato il codice un po 'durante il tentativo di eseguire il debug:Il membro con l'identità '' non esiste nella raccolta di metadati r nParameter nome:. Identità
[HttpPost]
public ActionResult Register(User model)
{
DateTime bla = new DateTime(2012, 12, 12);
try
{
User user = new User
{
gid = 1,
cid = 1,
firstName = model.firstName,
lastName = model.lastName,
email = model.email,
username = model.username,
password = model.password,
creationDate = bla,
active = 1
};
myContext.Users.AddObject(user);
myContext.SaveChanges();
}
catch (Exception ex)
{
throw ex;
}
return View();
}
I valori sono transmited conseguenza. tabella utenti:
[id] [int] IDENTITY(1,1) NOT NULL,
[cid] [int] NULL,
[gid] [int] NULL,
[firstName] [nvarchar](100) NOT NULL,
[lastName] [nvarchar](100) NOT NULL,
[email] [nvarchar](max) NOT NULL,
[username] [nvarchar](100) NOT NULL,
[password] [nvarchar](100) NOT NULL,
[creationDate] [datetime] NOT NULL,
[active] [int] NOT NULL,
VINCOLO [PK_ utenti _3213E83F0AD2A005] PRIMARY KEY cluster
ho cancellato tutte le chiavi esterne per essere sicuri che nulla colpisce esso. Sono sicuro che in un momento precedente funzionava, ma ora non riesco a capire dove si trovi. Si blocca durante l'esecuzione delle SaveChanges:
{"An error occurred while updating the entries. See the inner exception for details."}
{"The member with identity '' does not exist in the metadata collection.\r\nParameter name: identity"}
perché si sta un'istanza di un nuovo utente e l'impostazione delle proprietà? È possibile impostare direttamente le proprietà non vincolate al modello giusto? – VJAI
provato a utilizzare la soluzione di seguito (senza creare un'istanza di un nuovo oggetto Utente) ma non funziona. –
Il modello utente ha un ID proprietà? – VJAI