I have a (legacy) table with two guid fields. The second guid field can be null, but I want to auto-generate a non-dupe guid on insert using linq to sql. I have auto-sync set to “OnInsert” and Auto Generate Value set to True. But for some reason, it is not autogenerating/inserting guid values when the records are being put in the DB. I guess I could loop generating guids until I find one that is not in the DB and then add it in, but that does not seem very elegant. I am sure there is a better way to do this using linq to sql. Any suggestions on how to do this? Is it not making the guid because the nullable property is set to T?

I had a similar issue before, but learned how to change the properties of the ID field so that linq to sql could add the guid How do i prevent Linq from adding a GUID so that SQL server can do it? I can’t use that solution here because the guid in this case is nullable and is not the PK, so I can’t change the properties the way I did in the linked question.
If you use
Guid.NewGuid()to generate GUIDs, you should never generate two that are identical. If that happens, you will have just beaten absolutely incredible odds. It is safe to assume thatGuid.NewGuid()will return a GUID that nobody on the planet has ever generated before.