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 having a couple of different issues that I can't solve: 1) Sometimes when I delete an entity it removes it from the database, other times it doesn't and when I try to remove it again it throws an exception informing that the entity is already marked for deletion. Soft delete is not enabled. The entity in question has a ThroughAssociation and when deleting it, it just runs a select query on the association entity. 2) One of my entities throws a NullReferenceException when deserializing from a WCF service: System.NullReferenceException: Object reference not set to an instance of an object. at Mindscape.LightSpeed.Model.ToOneModel.(Entity ) at Mindscape.LightSpeed.Entity.Initialize() at Mindscape.LightSpeed.Entity.OnDeserializing(StreamingContext ) at ReadControlPointFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] ) at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Int32 id, RuntimeTypeHandle declaredTypeHandle, String name, String ns) at ReadDbEndpointEventArgsFromXml(XmlReaderDelegator , XmlObjectSerializerReadContext , XmlDictionaryString[] , XmlDictionaryString[] ) at System.Runtime.Serialization.ClassDataContract.ReadXmlValue(XmlReaderDelegator xmlReader, XmlObjectSerializerReadContext context) at System.Runtime.Serialization.XmlObjectSerializerReadContext.ReadDataContractValue(DataContract dataContract, XmlReaderDelegator reader) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator reader, String name, String ns, DataContract& dataContract) at System.Runtime.Serialization.XmlObjectSerializerReadContext.InternalDeserialize(XmlReaderDelegator xmlReader, Type declaredType, DataContract dataContract, String name, String ns) at System.Runtime.Serialization.DataContractSerializer.InternalReadObject(XmlReaderDelegator xmlReader, Boolean verifyObjectName) at System.Runtime.Serialization.XmlObjectSerializer.ReadObjectHandleExceptions(XmlReaderDelegator reader, Boolean verifyObjectName) at System.Runtime.Serialization.DataContractSerializer.ReadObject(XmlDictionaryReader reader, Boolean verifyObjectName) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameterPart(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameter(XmlDictionaryReader reader, PartInfo part, Boolean isRequest) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeParameters(XmlDictionaryReader reader, PartInfo[] parts, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.DataContractSerializerOperationFormatter.DeserializeBody(XmlDictionaryReader reader, MessageVersion version, String action, MessageDescription messageDescription, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeRequest(Message message, Object[] parameters) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.DeserializeInputs(MessageRpc& rpc) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet) This entity has 2 one-to-one relationships and both have DataMember tags. I looked at the entity's XML in the service trace and it looks fine. Is there something I am missing? 3) I am using VistaDB and if an error occurs once I continually get an exception that says "Nested transaction are not supported" even though the subsequent calls to the database work successfully. I am using a PerThread UnitOfWorkScope, so LightSpeed is handling opening/closing connections. 4) One of my models is being overwritten by nulls. It is an inherited model and it does not happen 100% of the time. Does saving the base entity overwrite the lower inherited entity? I believe this is being causing due to Optimistic Concurrency. I have implemented a change management system so this should no longer be a problem Please give me some direction. |
|
|
re 1: Are you calling SaveChanges after calling Remove (or is this being done at a later time?). The query which you are seeing is likely triggered by a lazy load of the association. re 2 and 3: These sound like potential bugs, is it possible for you to send through a small repro project which triggers these and I can investigate further and assuming they are bugs look to implement some fixes to cover these issues. re 4: Is this issue resolved for you? (Not sure if you have subsequently edited the post with the bold markup)
|
|
|
1: Yes after calling Remove, I immediately call SaveChanges. Sometimes it deletes the entity, and other times it doesn't 2 & 3: I will get you a project shortly. 4: Somewhat however I am having problems with loading a fresh entity (with associations) from a short-lived unit of work. It seems it's not possible to do if I want to dispose of the unit of work right after loading. I must have it short lived because I am using it to refresh the properties from the object that needs change management. |
|
|
re 1: This sounds very odd - is it possible to also look at a repro for this also? re 4: This is a problem because the UnitOfWork is disposed by the time you access the associations? If so can you look at eager loading the associations inline with the original entity fetch? http://www.mindscapehq.com/documentation/lightspeed/Performance-and-Tuning/Controlling-How-Entities-Load
|
|
|
1) Seems like I can not reproduce this in the sample project at will, so I am going to dig a little deeper and determine whether it is something on my end. EDIT: I was trying to remove models that were no attached to the UnitOfWork. 2) The sample project has been sent. 3) I was able to fix this problem by creating my own UnitOfWorkScope (in the sample project) and "resetting" the UnitOfWork object after the exception occurs. 4) Thanks I actually found a more streamline way of doing it before closing the connection. |
|
|
1 - When using the .Sum method on an entity collection, the database command includes the plural name of the table and not the singular (in our case) which results in a table not found exception. 2 - Piggyback from issue #3: The fix I implemented worked well but in the future I am going to have problems with lazy loading. Why isn't a new transaction used after encountering an error from a previous one after rolling back? When I get an error, subsequent errors are thrown as: Error 457 (Provider v. 4.3.3.34): Nested transactions not supported Error 450 (Provider v. 4.3.3.34): Cannot begin transaction instead of the actual exception that caused it. This is in VistaDB. 3 - When using adding a unique constraint after the column exists in the database, an exception is thrown when updating the database from the model: Incorrect syntax near the keyword UNIQUE. This only happens if the column already exists in the database. 4- After upgrading to 5.0 (not sure if it has anything to do with it or not), I am starting to see: Mindscape.LightSpeed.LightSpeedException: Expected single child entity but found multiple. What does this mean, and how do I correct it? Thanks for the help. |
|
|
re 1: Are you using the PluralizeTableNames option when configuring your LightSpeed context? re 2: We dont specifically use any transactions except for the KeyTable allocation, but that is self contained and is immediately committed on success of updating the KeyTable with the new block assignment so I am guessing that shouldnt be related to the issue you are seeing? Ordinarily we will either be enlisted via the ambient transaction scope or you will have specifically started a transaction. In both cases we leave managing failure to you since you have wider knowledge about what failure of the transaction means and presumably if you were looking to recover/retry you would be creating a new UnitOfWork or a new transaction as part of this. re 3: Can you generate a log of the SQL and attach this as this sounds like either a bug or a case where we cannot correctly perform the update so it sounds like something to change in either case - thanks! re 4: You will see this if you have a 1-1 association but more than one entity was found matching the parent Id in the database. This should not have anything to do with updating to LightSpeed 5 as this has always been a check on 1-1 associations.
|
|
|
1 - No the PluralTableNames option is not enabled. The entity collection works fine with other queries but when doing .Sum it always uses the plural form of the table. 2 - We aren't creating transactions either. We implemented our version of a PerThreadUnitOfWork in which each thread is given its own UnitOfWork. However, if an exception/error is thrown when changing the database then every exception/error after that first one throws the nested transaction exception given above instead of the actual error that caused it. Once we dispose of the UnitOfWork and create anew it works as expected. However, we can't dispose of the UnitOfWork because if there is a model that has not been fully loaded, due to lazy loading, then once the properties are accessed a disposed exception is thrown (due to us disposing the one that it was attached to and creating the new one). I have some other solutions to the problem including firing an event when the UnitOfWork is disposed so that the model knows to attach to the new one, but I'm not sure if that is the best approach. 3 - This happens when running a migration from the designer. How would I enable logging for the designer? 4 - I will look at my implementation again to make sure that it's not on my end, since this recently started happening. Thanks! |
|
|
Any news? |
|
|
Hi Greg, Sorry about the delay in getting back to you. re 1 - This sounds very odd. Calling .Sum() on an entity collection performs an in-memory operation after the collection is loaded (which is the same as just enumerating the collection for any other purpose) so there should be no difference between the calls but clearly something is going on here. Is it possible to get a small repro of this? re 2 - We re-throw any database exceptions we see verbatim, so Im assuming this is just what VistaDB is throwing back to us when an error is encountered. Im wondering what is actually causing the error though as it would probably be easier to try and deal with that. Are you able to reproduce the error fairly easily? re 3 - You wont be able to do this via the designer but this is possible if you run the migration via a Migrator instance. You can assign an IMigrationLogger instance to the Migrator.MigrationLogger property and then when executing the migrations it will call the LogSql method as it goes so you can capture the output there.
|
|
|
1 - So it does require the entity collection to be loaded in memory? 2 - Well it's errors that are being caused by various exceptions that I am having in the app. I can reproduce at will. 2 and 3 - I will just send a repro project with all my current problems. Thanks. |
|
|
re 1: Not specifically, but touching the entity collection will trigger a lazy load if it was not already loaded so the .Sum() call will do this and then will be operating in memory (Linq2Objects over the in-memory set).
|
|