Insert given with Entity and no Identity field

Asked

Viewed 182 times

0

I have this method to insert in the bank:

public virtual void Inserir(T item) 
        {
            contexto.Set<T>().Add(item);
            contexto.SaveChanges();
        }

And I have it in my Product entity, for example:

.......
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int IdProduto { get; set; }
.......

See that the DatabaseGeneratedOption is None and not Identity, that I did, because the field is not Identity, I didn’t think I could put for that reason and I don’t know if I would increase, but I did so, to follow the bank in the client, that has Identity in anything. How would I make the ID field go incrementing as I enter. I don’t want to gambiarra, to catch the atual + 1, that I don’t want to do. T is the type class

  • or is max + 1, or is generated in the bank, another way never seen

  • @Rovannlinhalis, good morning. I don’t have Identity in the bank, but if in my class, I do this DatabaseGeneratedOption.Identity, will increment, even this field in the bank will not be Identity?

  • @No, you have the two options that Rovann said.

  • @LINQ, thanks. In this case I will have to use the Max + 1 even, because in the customer’s bank I do not have Identity.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.