Click here to Skip to main content
13,199,026 members (39,414 online)
Rate this:
Please Sign up or sign in to vote.
See more:
        public ActionResult CreateUser( [Bind(Exclude="IdUtilisateur")Utilisateur UtilisateurCree)
            if (!ModelState.IsValid)
                return View();
            return RedirectToAction("CreateUser");

it returns an exception when creating!!!!!!!!!!!!
Posted 27-Dec-12 23:50pm
Updated 28-Dec-12 2:56am
Keith Barrow159.1K
Oleksandr Kulchytskyi 28-Dec-12 5:55am
How do you think , how can we help you from that little description??
Maybe it would be more efficient to add some exception message ??
Please accomplish your question
loylmed 28-Dec-12 7:47am
that has an exception whene i try to create an object the exception is here
loylmed 28-Dec-12 8:02am
"cannot insert value for identity colum in table 'users' when IDENTITY_INSERT in set to off'
but i search about the IDENTITY_INSERT but i can't find it !!!!!!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

<br />

But it's not relevant for EF, as i see, you have used

"I get the following error: Cannot insert explicit value for identity column in table 'People' when IDENTITY_INSERT is set to OFF."*

I think that the IDENTITY_INSERT is the Auto Increment functionality which is off. So, check the field PersonId in the database to see if it is an identity.

Besides, maybe this will fix your problem too.

public int UserId { get; set; }
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

The problem lies in the AddToUtilisateurs method, without this I cannot be 100% certain what is wrong.

Given the error message you describe somewhere along the line you are trying to an object's data where the record already exists. In your case to the object is being persisted in the users table. What is happening is the User object (UtilisateurCree?) already has an Id (probably the primary key on the table) set, whereas the database is expecting to generate it for you. If you are updating an existing user, you will need to get the user object from the data store, update the information and save, rather than trying to re-add it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171020.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100