0

I wrote this:


using (GuiaMovilEntities guiaEntity = new GuiaMovilEntities())
{
   try
   {
     Cliente cliente = 
        Cliente.CreateCliente(-1, datosCliente.Email, datosCliente.Password);
   }
   catch
   {
   }
}

It's unfinished.

If table Cliente (represented by Cliente object) has its first row (clienteID) as IDENTITY column.

Is it correct to put -1 as clienteID value?

Thanks!

4 Answers 4

2

Identity parameters are auto-generated - you shouldn't need to specify the value yourself.

Sign up to request clarification or add additional context in comments.

3 Comments

So you should use the default static Create method that the entity framework object creates or do you just enter in 0 as the ID?
I'd imagine that if it's auto-generated, you don't need to enter anything at all. Certainly don't assign 0 to the ID.
Hmm doesn't seem to be the case for me when I generate an .edmx from the database I have, though perhaps that's another question.
1

Here's another option:

Cliente cliente = new Cliente
{
    Email = datosCliente.Email,
    Password = datosCliente.Password
};

Comments

0

No, you don't ever need to set the Id. Remove the parameter from the factory method and leave the Id value as the default (zero in this case I imagine).

Comments

0

if you really want a undefined id which is not 0, such as -1, you could implement the default constructor for your entity and set it there.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.