The number of ThisKey columns is different from the number..

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
tleese22
Posts: 8
Joined: Fri 19 Feb 2010 02:58

The number of ThisKey columns is different from the number..

Post by tleese22 » Fri 19 Feb 2010 03:02

I'm very new to DevArt dotConnect and LINQ to SQL and I'm getting the exception below which is a little cryptic. Any ideas how to solve this?

System.InvalidOperationException was unhandled
Message="The number of ThisKey columns is different from the number of OtherKey columns for the association property 'Foo' in the type 'Bar'."
Source="Devart.Data.Linq"
StackTrace:
at Devart.Data.Linq.Mapping.t..ctor(q A_0, AssociationAttribute A_1)
at Devart.Data.Linq.Mapping.q.n()
at Devart.Data.Linq.Provider.Query.ai.a(bk A_0, MetaDataMember A_1)
at Devart.Data.Linq.Provider.Query.ai.a(SqlExpression A_0, MetaType A_1, List`1& A_2, List`1& A_3, SqlExpression& A_4, IList`1 A_5)
at Devart.Data.Linq.Provider.Query.ai.b(SqlExpression A_0, MetaType A_1, List`1& A_2, List`1& A_3, SqlExpression& A_4, IList`1 A_5)
at Devart.Data.Linq.Provider.Query.ai.a(ag A_0, IList`1 A_1)
at Devart.Data.Linq.Provider.Query.ai.a(MetaType A_0, ITable A_1, IList`1 A_2)
at Devart.Data.Linq.Provider.Query.ai.a(au A_0)
at Devart.Data.Linq.q.a(au A_0, List`1 A_1)
at Devart.Data.Linq.q.a(MetaDataMember A_0, au A_1, List`1 A_2)
at Devart.Data.Linq.Provider.SelectionBuilder.a(bk A_0)
at Devart.Data.Linq.Provider.SelectionBuilder.a(SqlExpression A_0)
at Devart.Data.Linq.Provider.SelectionBuilder.BuildSelection(SqlExpression selection)
at Devart.Data.Linq.Provider.j.a(n A_0, SqlExpression A_1)
at Devart.Data.Linq.Provider.j.a(Type A_0, SqlExpression A_1, n A_2, Type A_3, Type A_4)
at Devart.Data.Linq.Provider.DataProvider.b.a(List`1 A_0, n A_1, SqlNode A_2)
at Devart.Data.Linq.Provider.DataProvider.b..ctor(a A_0, n A_1)
at Devart.Data.Linq.Provider.DataProvider.a(Expression A_0)
at Devart.Data.Linq.Provider.DataProvider.i(Expression A_0)
at Devart.Data.Linq.DataQuery`1.i()

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 19 Feb 2010 15:06

This problem usually indicates that the association is built between two entities and the number of columns in a key
on one end does not correspond to the number of the columns in key on the other end.
If you have added this association manually then modify it to be valid.
If the association was generated by our Entity Developer, please let us know its version
and send me the script of tables producing the error (support * devart * com, subject "ED: Wrong association") or post the script here.

tleese22
Posts: 8
Joined: Fri 19 Feb 2010 02:58

Post by tleese22 » Mon 22 Feb 2010 22:48

I had edited an association to be OneToOne rather than OneToMany and this is when I saw the exception. The association should be a valid OneToOne but when I add the table in design view it creates the OneToMany association. Any ideas what needs to change with the tables in order to get this to be OneToOne?

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 23 Feb 2010 10:41

Please show the code you get the error in.
I am unable to reproduce the error using simple OneToOne associations' tests.

jpdomenge
Posts: 12
Joined: Fri 12 Mar 2010 08:17

Post by jpdomenge » Fri 25 Jun 2010 21:29

We are having the same issue with LinqConnect trial version (1.0.0.36).

This issue happens when we try to load data on a table which has an association with another one.

We are working on an Oracle 11gR2 database.

If we have only one table in the model, the query works fine but when we add the other table with an association, it failed.

Here is the StackTrace:
System.InvalidOperationException was unhandled
Message=The number of ThisKey columns is different from the number of OtherKey columns for the association property 'ECde' in the type 'Commande'.
Source=Devart.Data.Linq
StackTrace:
at Devart.Data.Linq.Mapping.s..ctor(p A_0, AssociationAttribute A_1)
at Devart.Data.Linq.Mapping.p.n()
at Devart.Data.Linq.Mapping.MetaTypeBase.c(MetaDataMember A_0)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Devart.Data.Linq.Mapping.MetaTypeBase.get_Associations()
at Devart.Data.Linq.DataContext.a(MetaTable A_0)
at Devart.Data.Linq.DataContext.b(MetaTable A_0)
at Devart.Data.Linq.DataContext.GetTable[TEntity]()
at DalTest.Data.DTO.MagistorDataContext.get_Commandes() in D:\DalTest\DalTest.Data\DTO\MagistorDataContext.Designer.cs:line 89
at DalTest.Data.DAO.DAOCommande.SelectAll() in D:\DalTest\DalTest.Data\DAO\DAOCommande.cs:line 65
at DalTest.WPF.ViewControl.ViewCommande.UserControl_Loaded(Object sender, RoutedEventArgs e) in D:\DalTest\DalTest.WPF\ViewControl\ViewCommande.xaml.cs:line 38
at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
at MS.Internal.LoadedOrUnloadedOperation.DoWork()
at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at DalTest.WPF.App.Main() in D:\DalTest\DalTest.WPF\obj\x86\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 30 Jun 2010 15:31

I will send you a test project with two simple tables connected with a one-to-one association. Please specify what should be changed in this project or send us your sample so that we are able to reproduce the issue.

The tables are created as

Code: Select all

CREATE TABLE SCOTT.DEPT (
  DEPTNO NUMBER(4),
  DNAME VARCHAR2(14),
  LOC VARCHAR2(13),
  CONSTRAINT PK_DEPT PRIMARY KEY (DEPTNO));

CREATE TABLE SCOTT.DEPT2 (
  DEPTNO NUMBER(4),
  DNAME VARCHAR2(14),
  LOC VARCHAR2(13),
  CONSTRAINT PK_DEPT2 PRIMARY KEY (DEPTNO));

jpdomenge
Posts: 12
Joined: Fri 12 Mar 2010 08:17

Post by jpdomenge » Wed 30 Jun 2010 19:45

You can try with these tables, it should (not) work
CREATE TABLE "SCOTT"."COMMANDE_DEMO"
(
"ID_CDE" NUMBER NOT NULL ENABLE,
"ID_SOC" NUMBER NOT NULL ENABLE,
"N_CDE" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"DATE_DDEE" DATE NOT NULL ENABLE,
"AFAC_INDIVIDU" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"AFAC_RAISON_SOCIALE" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"AFAC_ADRESSE1" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"AFAC_ADRESSE2" VARCHAR2(50 BYTE),
"AFAC_ADRESSE3" VARCHAR2(50 BYTE),
"AFAC_CP" VARCHAR2(15 BYTE) NOT NULL ENABLE,
"AFAC_VILLE" VARCHAR2(50 BYTE) NOT NULL ENABLE,
"AFAC_PAYS" VARCHAR2(50 BYTE) NOT NULL ENABLE,

CONSTRAINT "PK_COMMANDE_BUG" PRIMARY KEY ("ID_CDE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 262144 NEXT 262144 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "MS_INDX_TBS" ENABLE,
CONSTRAINT "UC_N_CDE_ID_SOC_BUG" UNIQUE ("N_CDE", "ID_SOC") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 NOLOGGING COMPUTE STATISTICS STORAGE(INITIAL 262144 NEXT 262144 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "MS_MAIN_TBS" ENABLE
);


CREATE TABLE "SCOTT"."LGN_CDE_DEMO"
(
"ID_LGN_CDE" NUMBER NOT NULL ENABLE,
"ID_CDE" NUMBER NOT NULL ENABLE,
"ID_ART" NUMBER NOT NULL ENABLE,
"QTE_CDE" FLOAT(126) DEFAULT 0 NOT NULL ENABLE,
CONSTRAINT "PK_LGN_CDE_BUG" PRIMARY KEY ("ID_LGN_CDE") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 81920 NEXT 262144 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "MS_INDX_TBS" ENABLE,
CONSTRAINT "FK_LGN_CDE_LGN_BUG" FOREIGN KEY ("ID_CDE") REFERENCES "SCOTT"."COMMANDE_DEMO" ("ID_CDE") ON
DELETE CASCADE ENABLE
)
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
(
INITIAL 262144 NEXT 262144 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
)
TABLESPACE "MS_MAIN_TBS" ;
In fact I guess the problem is that devart is mixing Primary Key with the constraint Unique.

So in one table we have a key with 3 columns (primary key + Unique) and in the other table we have a key on only one column which throw the exception.

I have to investigate on my side why the table is defined that way but Oracle works fine in this configuration.

Best Regards.

P.S. I have not the correct configuration to run the devart project so I have not tested what i assume above.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Thu 01 Jul 2010 14:12

Thank you for your assistance, we've reproduced the problem. We will fix it in one of the nearest builds.

As a workaround, you can uncheck the 'Entity Key' check boxes for the fields that do not belong to the primary key.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Fri 09 Jul 2010 17:16

We've fixed the problem, the fix is available in the latest 5.70.146 build of dotConnect for Oracle. The build can be downloaded from
http://www.devart.com/dotconnect/oracle/download.html
(the trial version) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For more information on improvements and fixes available in the 5.70.146 version, please refer to
http://www.devart.com/forums/viewtopic.php?t=18424

Post Reply