This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have another issue for the collection. I have a context with 7 tables. Two of them are Family and Members (of the family). I have a Members.csv with members info from where the two tables must be nurtured. The csv has mixed data in every record (person and family data in every record). I must separate the person data from the family data and then feed each table accordingly. Well, the family id comes in the csv file and because the requirements I must use that id - other tables depends on that. I try with all the four identity generation methods but none of them allows to set the identity by hand (programmatically). In brief, I need to take the IdFamily from the csv. All the rest of the tables may have another id generation method. I can't see how GenerateId can be override to perform this. Somebody may help?? I can't figure out how to do this thing. |
|
|
You need to override GeneratedId() only on the Family entity. The usual idiom for your scenario is to read the required ID into a transient field and then refer to that when it is needed: partial class Family { For all other entities, you can leave GeneratedId() and the entity Identity Method alone and just set your identity method of choice at the LightSpeedContext level (the default is KeyTable). Also, just to state the obvious, you must not use the IdentityColumn method, because then you won't be able to insert Family entities with the specific ID you need -- the database will blow those IDs away. KeyTable is usually the best choice anyway, and can be nicely tuned to work efficiently with bulk inserts like yours. |
|
|
I delayed a while to provide feedback because I was implementing this solution. It works great, really, but now I have a collateral problem. One of the tables where this method was implemented has an string id. No problem with the GeneratedId method, but as soon as I try to stablish a relation with other tables and try to update the database it says that the relation can't be stablished because the type of the id is different. I got a workaround for this going to the SQL Server Management Studio, adding the foreign key to the table, stablishing the relation and updating the LightSpeed from the database. The workaround works well, but I wonder why I can't the same result from the model itself. Any idea? |
|
|
Any idea, suggestion, recommendation, counsel, advice, drop of wisdom or spark of light? |
|
|
Could you provide us with a small model that exhibits the issue so we can try to reproduce this here please? Thanks! |
|