0

I'm looking to update a column in a table from a null state to a unique ID which would represent the row being locked. Is there a simple means of doing this?

Thanks

Edit for clarification: This is pretty much what i'm looking for. After thinking about it for a while i'm pretty much of the opinion it should just be broken off into a separate table and referenced via a foreign key.

Pk  | column  | uniqueId
1   | useless | <DBNULL>
2   | random  | <DBNull>
--Update occurs
1   | useless2| 1
2   | random  | <DBNULL>
--Update occurs
1   | useless3| 2
2   | random  | <DBNULL>
--update occurs
1   | useless3| 2
2   | random2 | 3
Highstead
  • 2,291
  • 3
  • 26
  • 30
  • entities require unique keys/ID-s, and i.e. non null - you can do that with other non-key column. – NSGaga-mostly-inactive Apr 18 '12 at 20:59
  • The entity has a unique key/id. I am hoping to have another column represent a locked state. This column would ideally be unique, and since i can't trust a hash to do this i was hoping for an alternative. – Highstead Apr 18 '12 at 21:06
  • Can't you just use the primary key value? – Gert Arnold Apr 18 '12 at 21:30
  • @GertArnold OP needs it to be null up to some point, as I understood. – NSGaga-mostly-inactive Apr 18 '12 at 21:37
  • @NSGaga - I mean: use the PK value to fill the "lock" column. But I miss the bigger picture here, to be honest. – Gert Arnold Apr 18 '12 at 21:39
  • @GertArnold Thought about that, i'm thinking at that point might as well just use a bit/boolean as a flag. – Highstead Apr 18 '12 at 21:45
  • 1
    @GertArnold you mean duplicate - null or key ID - that makes sense too actually - but as you just said, that's more of a bit/boolean. So custom Guid maybe safer if some real ID is needed, aside of key or key/identity may not be inconvenient - and bool is a very simple option - unless it has some downsides - I'd vote for that actually. as simple as possible. The OP may just need to 'flag' the record. – NSGaga-mostly-inactive Apr 18 '12 at 21:48

2 Answers2

0

I think (if I'm getting right what you're after),
your best option is using Guid column - and most likely having to custom implement the Guid ID from the EF/C# side - so that you could keep the column 'null' also when wanted.

Closest to what you need is what's described already in this question,

Does Entity Framework 4 Code First have support for identity generators like NHibernate?

Community
  • 1
  • 1
NSGaga-mostly-inactive
  • 14,052
  • 3
  • 41
  • 51
0

If you only want to represent rows being "locked" or not, the simple means of doing it is to use a bit/boolean column.

There is no need for uniqueness as you already have a Primary Key on the table.

ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235