I am having this Entity (both in database and Entity Framework):
public class LanguageValue
{
public int ID { get; set; }
public long Key { get; set; } // bigint in database
public int LanguageID { get; set; } // FK with a Language table in database
public string Value { get; set; } // nvarchar(MAX) in database
public bool Active { get; set; } // bit in database
}
I have already read this article, but my problem is a bit different: EF6: How to generate a unique number automatically based on entity Id
My Key
column does not have unique constraint, because there can be multiple rows with the same Key
value. For example:
ID Key LanguageID Value
---------------------------------------------------
1 1 1 Name in Language 1
2 1 2 Name in Language 2
I cannot use a Mapping table to enforce a FK instead of Key
because multiple tables uses this same table (Product's Name, Category's Name, Article's Content).
Now whenever I need to insert a Product
or Category
record, I need to insert their corresponding Language Value. However, I have yet to find a way to generate a Key that is unique among them, and more over, need to be unique in case two insert are being processed at once (for example, adding a Product and Category at the same time).
I am thinking about Guid
, should that be my safe bet with RNG, or is there any better way/design for achieving it?