I have a CodeFirst Entity Framework database. I am generating a GUID myself, and the following is defined in the model:
[Required, Key, DatabaseGenerated(System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedOption.None)]
public string BatchId { get; set; }
My goal – is there a way I can first validate that the GUID does not already exist in the database, and then create a new GUID as needed until a unique one is found?
By all means read the DB first to be sure to be sure. But E=MC^2 or your money back.
Nope not found….
Let us know when you get a dup if using Guid.New();
Btw do you plan on using strings for your gUid or type Guid / DBType UniqueIdentier ? If so, You should reconsider the type chosen.