Custom Key Generator always not found assembly

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Custom Key Generator always not found assembly

Post by navirius » Thu 18 Jul 2013 03:16

I have little project with this scenario
1. I create CustomGenerator with name MemberIdGenerator extend from KeyGenerator
2. Entity class namespace and MemberIdGenerator namespace have same namespace (namespace: eCoMaxDB)
3. I set entity primary ke to CustomGenerator with Class Name:"eCoMaxDB.MemberIdGenerator" with single passing parameter
4. I have already set on model designer for custom generator, and generated class with primary key attribute like this

Code: Select all

[Column(Storage = "_MemberId", CanBeNull = false, DbType = "VARCHAR(50) NOT NULL IDENTITY", IsPrimaryKey = true)]
[Devart.Data.Linq.Mapping.CustomGenerator(ClassName = "eCoMaxDB.MemberIdGenerator", Parameters = new object[] { URI })]
but the problem is, at runtime it always complain, "Can not load type 'eCoMaxDB.MemberIdGenerator' from assembly 'Devart.Data.Linq'

Code: Select all

System.TypeLoadException was unhandled
  HResult=-2146233054
  Message=Could not load type 'MemberIdGenerator' from assembly 'Devart.Data.Linq, Version=4.2.272.0, Culture=neutral, PublicKeyToken=09af7300eec23701'.
  Source=mscorlib
  TypeName=MemberIdGenerator
  StackTrace:
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
       at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
       at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
       at System.Type.GetType(String typeName, Boolean throwOnError)
       at Devart.Data.Linq.Mapping.CustomMetaKeyGenerator.a(DataContext A_0, MetaDataMember A_1)
       at Devart.Data.Linq.Engine.x.a(MetaDataMember A_0)
       at Devart.Data.Linq.Engine.h.a(IKeyGeneratorManager A_0)
       at Devart.Data.Linq.Engine.b6.a(IObjectEntry[] A_0, ConflictMode A_1, a A_2)
       at Devart.Data.Linq.Engine.b6.a(ConflictMode A_0)
       at Devart.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
       at eCoMaxDBManager.MemberManager.Save(MemberData data) in F:\My Document\Visual Studio 2010\Projects\eCoMaxDotNetSQLServer\eCoMaxDB\MemberManager.cs:line 42
       at TestConsole.Program.Main(String[] args) in F:\My Document\Visual Studio 2010\Projects\eCoMaxDotNetSQLServer\TestConsole\Program.cs:line 50
       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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
- is any specific requirement using custom generator?
- can I request sample project using custom generator?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Thu 18 Jul 2013 08:34

You are getting this error because when defining a custom generator class for the MemberId property you don't have the name of the assembly after a comma since the LinqConnect runtime has to be able to find your class, e.g.:

Code: Select all

[Column(Storage = "_MemberId", CanBeNull = false, DbType = "VARCHAR(50) NOT NULL IDENTITY", IsPrimaryKey = true)]
[Devart.Data.Linq.Mapping.CustomGenerator(ClassName = "eCoMaxDB.MemberIdGenerator, eCoMaxDB", Parameters = new object[] { URI })]
For more information please refer to this topic in LinqConnect documentation.

Also, we are sending you a sample project with custom key generators to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter.

navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: Custom Key Generator always not found assembly

Post by navirius » Thu 18 Jul 2013 13:19

thx mariial, missing that assembly name, because at documentation it doesnt explain about that,

check your example project

navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: Custom Key Generator always not found assembly

Post by navirius » Fri 19 Jul 2013 03:05

I got another, you can say glitch, about keygenerator,

1. if I edit Parameters via properties in model editor, it always short by parameter name, ex. I have two parameter A and B, but in parameter order I want to B as first parameter then A, but itu always ordered A first then B, it always order by name, Can I order my parameter without that restriction?

2. every time I change my parameter order, add parameter, remove parameter, my model like never change, so I can update my class model code with save, I must move one entity position then save it, its annoying too

3. if my custom keygenerator want to access current inserted data instance field value, how?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Mon 22 Jul 2013 10:13

We are working on our documentation.
As for your other remarks:
1) We have reproduced this issue. We will investigate it and inform you about the results as soon as possible.
2) This is the designed behaviour for the parameters of custom generators, which user adds manually. It is related to the peculiarities of the internal implementation.
3) If we correctly understand you, you want to get the last inserted value by your custom generator. If so, it can be get it in the Generate() method of your custom generator class, e.g.:

Code: Select all

public override object Generate()
        {
           ...
            try
            {
                var command = connection.CreateCommand();
                command.Transaction = DataContext.Transaction;
                command.CommandText = "SELECT NEXT VALUE FOR " + sequenceName;
                int LastValue = System.Convert.ToInt32(command.ExecuteScalar());
                return LastValue;
            }
            ...
        }
If it is not what you mean, please specify your question in more details.

navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: Custom Key Generator always not found assembly

Post by navirius » Mon 22 Jul 2013 14:07

for my question number 3, I mean this way
in my custom keygenerator, generate key with current instance data
ex.
1. I have data class MemberData with MemberId with custom generator and Location as string data
2. I instantiate new MemberData and fill Location (eg. "A" or "B" depend on user location)
3. On insert data, I want generate MemberId depend on location, so It can generate with format [Location]-[counter] ex. A-00001 or B-00001

that exactly what I mean, how can I access current field data instance within keygenerator

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Tue 23 Jul 2013 10:33

Thank you for the additional information. We are sending you a small test project to the e-mail address you have provided in your forum profile. Please check that the letter is not blocked by your mail filter. Please tell us if this helps.

navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: Custom Key Generator always not found assembly

Post by navirius » Tue 23 Jul 2013 14:27

thanks for your example code Mariial, but unfortunately, that's not I'm looking for,
I design my application for multiuser, and probably multi instance of class data

Code: Select all

TestMContext.Table1 data1 = new TextMContext.Table1{Value="A"};
TestMContect.Table2 data1 = new TextMContext.Table2{Value="B"};
dt.Table1.InsertOnSubmit(data1);
dt.SubmitChanges();
dt.Table1.InsertOnSubmit(data2);
dt.SubmitChanges();
I hope I can generate a key like that, not from static class field,
and keygenerator can read value of "Value" field every instance
Is it possible?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Wed 24 Jul 2013 12:18

Currently this functionality is not available for LinqConnect custom generators. We will consider the possibility to implement it, but we can't tell any timeframe at the moment. We will inform you when any results are available.

As a workaround, you could try using the scenario without a custom key generator. We have sent you a sample with such variant of a solution. Please check it and tell us if this helps.

navirius
Posts: 16
Joined: Sat 29 Jun 2013 11:50

Re: Custom Key Generator always not found assembly

Post by navirius » Thu 25 Jul 2013 03:08

I really appreciated for your attention,

I hope key generator break if model view closed, fixed soon...because is annoying if I must set everytime for keygenerator setting

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Thu 25 Jul 2013 05:17

navirius wrote:I hope key generator break if model view closed, fixed soon...because is annoying if I must set everytime for keygenerator setting
This issue has been fixed. The fix will be included in the next build of LinqConnect. We will inform you when it is available for download.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Key Generator always not found assembly

Post by MariiaI » Thu 08 Aug 2013 12:09

New build of LinqConnect 4.2.306 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=27702.

Post Reply