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 a mysql table, where the user is allowed to specify the value for the primary key (not an auto-increment column). How do I configure that table in the model so that I can specify the value when the object is constructed? |
|
|
You need to override the Entity.GeneratedId() method. LightSpeed calls this method when it needs to assign an ID to an entity. Note that it gets called as soon as a new entity gets added to a unit of work, so any data it requires has to be ready pretty early in the entity lifecycle. E.g. partial class Book { |
|
|
I did exactly what you suggested, and it doesn't insert any rows for that table now. public partial class Site
am I doing something wrong here? |
|
|
What you've got there looks fine. What code are you using to insert Site entities? If you attach a logger (unitOfWork.Context.Logger = new TraceLogger();), do you see any SQL being emitted? Also, what is your LightSpeedContext.IdentityMethod? LightSpeed does some special handling if the identity method is IdentityColumn: if that's the case, try setting Site's Identity Method to something other than IdentityColumn (it doesn't matter what). |
|
|
I can’t seem to find the TraceLogger class you refer to anywhere. Can you give me a hint as to what namespace it’s found in? Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4
|
|
|
so I found the TraceLogger class, but now I'm confused about how to actually make it work. how do I get it to log sql to a file, and where will I find that file once it's created? |
|
|
TraceLogger logs to Debug.Trace. By default, this prints to the Visual Studio output window when running under a debugger, and does nothing in "normal" running. Since you just want to see what output's being generated, running under the debugger and looking at the Output window should suffice for your immediate requirement. However, if you do need to log SQL to a file, either: * In your configuration file, add a trace listener which writes to a file (see for example TextWriterTraceListener or FileLogTraceListener); or * Create your own implementation of Mindscape.LightSpeed.Logging.ILogger which writes to a file, and use that instead of TraceLogger. |
|
|
I changed the IdentityMethod to Sequence, and it started working. Thanks a lot. |
|
|
Hi Ivan, In this example, is there a way to get _pendingId assigned to the Entity in the Book() constructor so that the Id property returns the value of _pendingId immediately after the Book is instantiated? The Id property is read-only, and GenerateId() is not invoked until the entity goes into a unit of work. So the time between constructor and unit of work the Id property doesn't reflect _pendingId. Many thanks, Derek |
|
|
Hmm, good point. Unfortunately this isn't possible with our current architecture. Depending on your usage pattern you might be able to fake it by shadowing the Id property: public new object Id { but that won't be polymorphic if you're mixing Books with other entities. |
|