sql - Difference between creating Guid keys in C# vs. the DB -


We use Gates as the primary key for entities in the database. Traditionally, we have followed a pattern of setting an ID for an entity during the INSERT, I think most of the reasons are that you usually have an auto-arrangement field or whatever you do By handling things.

I am looking for as much as possible that the object is highly capable of assigning the key to the code for two main reasons during the creation:

  1. You know that Once running an object constructor, all this field has been initialized, you never bring "semi-baked" objects.
  2. If you need a batch of operations, some of these objects depend on knowing the key, for the database.

Is there no compelling reason to work no to work this way? That is, when the grid is used in the form of keys, is the database a good reason to leave important assignments?

Edit: A lot of people have strong opinions on whether the grid should be used for pids (which I knew), but it is actually my question There was no issue.

In addition to the clustering issue (which is not the problem if you indexed properly), I have not seen any compulsive reasons to avoid making the key in the application layer.

I think you are doing fine by creating them on the client side. As you have mentioned, if you do this to DB, then you have to find some way to get that key (nobody really can think). If you were using an identity, you can call, which you can use to get the latest one created for the table, but I'm not sure that such a grid exists.


Comments