How can i trap error on creating unique id ?
i used guid instead of auto increment, but i don't know how to trap the error on duplication, i created some code on getting data in SQL using advance linq to know if my id created is exist, but in the end i still have an error.
somebody help me and give me some tip/ link of what is best to use. here my sample code below.
var nid = Guid.NewGuid();
var getCartIds = _cartUoW.ShoppingCarts.Get().ToList();
bool exist = false;
do
{
nid = Guid.NewGuid();
exist = getShoppingCartId.Any(x => x.Id == nid);
} while(exist);