Exception thrown in a entity that contains a complex class during a update

Exception thrown in a entity that contains a complex class during a update

Postby ashlar64 » Fri 17 Jan 2014 05:55

Hello,

I am getting a exception like this when I try to do a update a entity that contains a complex class:

Devart.Data.Linq.LinqCommandExecutionException was unhandled by user code
HResult=-2146233088
Message=Error on executing DbCommand.
Source=Devart.Data.Linq
StackTrace:
at Devart.Data.Linq.LinqCommandExecutionException.CanThrowLinqCommandExecutionException(String message, Exception e)
at Devart.Data.Linq.DataProvider.b(String A_0, IEnumerable`1 A_1, IEnumerable`1 A_2, Boolean A_3)
at Devart.Data.Linq.Engine.SubmitCommandBuilder.a(String A_0, IEnumerable`1 A_1, IEnumerable`1 A_2, Boolean A_3)
at Devart.Data.Linq.Engine.SubmitCommandBuilder.a(String A_0, IEnumerable`1 A_1, Boolean A_2)
at Devart.Data.Linq.Engine.b5.a(IObjectEntry[] A_0, ConflictMode A_1, a A_2)
at Devart.Data.Linq.Engine.b5.a(ConflictMode A_0)
at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at MCore.mPlaneParameter.CreatePlanes(MContext m) in e:\code\Nullspace\MCore\Entities\mPlaneParameter.cs:line 240
at MCreation.MCreator.<>c__DisplayClass1.<CreateNewMultiverse>b__0(Int32 i) in e:\code\Nullspace\MCreation\MCreator.cs:line 95
at System.Threading.Tasks.Parallel.<>c__DisplayClassf`1.<ForWorker>b__c()
InnerException: System.Data.SqlClient.SqlException
HResult=-2146232060
Message=The variable name '@chk1' has already been declared. Variable names must be unique within a query batch or stored procedure.
Must declare the scalar variable "@p3".
Must declare the scalar variable "@p4".
Must declare the scalar variable "@p5".
Must declare the scalar variable "@p6".
Must declare the scalar variable "@p7".
Must declare the scalar variable "@p8".
Must declare the scalar variable "@p9".
Must declare the scalar variable "@p10".
Must declare the scalar variable "@p11".
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=134
Procedure=""
Server=(local)\Blah
State=1
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at System.Data.SqlClient.SqlDataReader.get_MetaData()
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at Devart.Data.Linq.DataProvider.b(String A_0, IEnumerable`1 A_1, IEnumerable`1 A_2, Boolean A_3)
InnerException:


Here is some code in a sample project I wrote that demonstrates this exception.

Code: Select all

using Context;
using System.Windows;

namespace WpfApplication1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            string connectionString = @"data source=(local)\Blah;initial catalog=MTest;integrated security=True;persist security info=True";

            DataContext m = new DataContext(connectionString);
            m.Connection.Open();
            m.DeleteDatabase(true, false);
            m.CreateDatabase();

            {
                Class1 c1 = new Class1();
                //c1.PlanetaryAttribute.Gravity = ePlanetaryAttributeAmount.Heavy;

                Class1 c2 = new Class1();
                m.Class1s.InsertOnSubmit(c1);
                m.Class1s.InsertOnSubmit(c2);
                m.SubmitChanges();
            }

            foreach (Class1 c in m.Class1s)
            {
                c.PlanetaryAttribute.Gravity = ePlanetaryAttributeAmount.Heavy;
            }

            m.SubmitChanges();
        }
    }
}



The odd thing is that if I uncomment that commented line the exception is not thrown and it works. I could send you the sample project I made if that would be helpful. Also another odd thing is if I create a new DataContext and use that new datacontext in the foreach loop that works as well...

Thanks

---Dave
ashlar64
 
Posts: 75
Joined: Thu 04 May 2006 18:56

Re: Exception thrown in a entity that contains a complex class during a update

Postby MariiaI » Fri 17 Jan 2014 09:34

Thank you for the report on this. We have reproduced this issue. We will investigate it and inform you about the results as soon as possible.
As a temporary workaround, please try usis this code:
Code: Select all
DataContext m = new DataContext(connectionString);
m.MaxBatchSize = 1;
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Exception thrown in a entity that contains a complex class during a update

Postby MariiaI » Thu 30 Jan 2014 14:28

The bug with performing updates and deletes, when concurrency check is used for not-primary key columns, and the commands are combined to run in batches, is fixed.
New build of LinqConnect 4.4.428 is available for download now!
It can be downloaded from http://www.devart.com/linqconnect/download.html (trial version) or from Registered Users' Area (for users with active subscription only)
For more information, please refer to http://forums.devart.com/viewtopic.php?f=31&t=28831.
MariiaI
Devart Team
 
Posts: 1472
Joined: Mon 13 Feb 2012 08:17


Return to LinqConnect (LINQ to SQL support)