I have a class Item and a class ItemAttribute, where Item has a property of type ItemAttribute.
ItemAttribute only has two properties, a Guid called ID and a string called name. The idea here is that I want to store a table called ItemAttributes that contains a list of unique strings.
My question is, if I save an Item that references an ItemAttribute that already exists in the database, how can I make it reference the already existing ItemAttribute, rather than creating a new one?
Update
Kristoffer Ahl better expresses what I’m trying to do in this post.
It looks like what I want to do isn’t possible 🙁
So, let’s abstract things a bit 🙂 The purpose of the ItemAttributes table is simply to reduce duplication, so I can just store each attribute once, and link to the Item using an identifier.
If I could generate a unique ID for each attribute I could assign this ID and code – that should work!
But how can I generate a unique ID for a string? The ID must be consistent, such that the same ID will be generated for the same string each time.
I solved this using SaveOrUpdateCopy.
The only thing with this approach is that I need to assign an ID to the ItemAttribute objects before calling SaveOrUpdateCopy.