views:

552

answers:

4

Hi!

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!

A: 

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).

James L
+1  A: 

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

Dmitri Nesteruk
A: 

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.

Davy Landman
+1  A: 

Here's another option:

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