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
|
Hello, I am attempting to do an insert in my MySQL database. I set the 'id' attribute like this: myobj.id = "stringIdHere"; The start of the auto generated class looks like this: [Table("table_name", IdColumnName="My_Id")] At runtime, I encounter this error, referring to the myobj.id line above: Error 1 Property or indexer 'Mindscape.LightSpeed.Entity<string>.Id' cannot be assigned to -- it is read only Out of curiosity I commented that line out, only to run into this error, referring to the following line: unitOfWork.Add(myItem); // Gives the error below Table 'MyDatabase.KeyTable' doesn't exist Other than these 2 problems I would like to say that my experience with LightSpeed thus far has been great, and I hope to find some assistance here so I can move forward and continue to work with your product. |
|
|
Hello Jeff, Thanks for the positive feedback. As you have noticed, LightSpeed doesn't allow you to set an entity ID explicitly. Instead, LightSpeed will generate the entity ID automatically when required (e.g. on insert). The way that LightSpeed generates IDs is determined by the LightSpeedContext.IdentityMethod. (You can override this on a per-entity-type basis, if different tables need different identity strategies, but this is the exception rather than the rule.) The default IdentityMethod is KeyTable, which relies on the database containing a table called KeyTable which LightSpeed can use to allocate blocks of IDs. You're seeing an error because this table doesn't exist. You can create this table using the scripts provided in the LightSpeed Providers directory (there's one for MySQL in there). However, KeyTable generates integer IDs rather than string IDs (LightSpeed is opinionated software!). To use string IDs, you'll need to use another IdentityMethod such as Guid. Check out the IdentityMethod enumeration and Help Topics > Identity Generation in the user guide for more info. Hope this makes sense and thanks again for the feedback. |
|