This is a migrated thread and some comments may be shown as answers.

Unable to cast Exception Q2 2012 SP2

12 Answers 167 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eloy Paredes
Top achievements
Rank 1
Eloy Paredes asked on 02 Sep 2012, 02:54 AM
I have an application developed with:
  • Windows 7, 64 bits
  • Visual Studio 2010, .NET Framework 4.0
  • PostgreSQL 9.1
  • Telerik OpenAccess Q2 2012 Free Edition
this application work pefectly.

I change my plataform to:
  • Windows 8, 64 bits
  • Visual Studio 2012, .NET Framework 4.0
  • PostgreSQL 9.1
  • Telerik OpenAccess Q2 2012 SP2 Free Edition
I migrate application to this plataform, and update all reference, but when run i see this exception:

Unable to cast object of type 'OpenAccessRuntime.Relational.RelationalNewObjectOID' to type 'System.Collections.ICollection'

there any way to solve this error?

thanks in advance and sorry for my bad English

12 Answers, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 03 Sep 2012, 09:19 AM
Hello Eloy Paredes,

This is a known bug which will be fixed with the next version. This only occurs if you create an object and assign a reference to the object, before the object is added to the context. If you add the reference on the object after your object is added to the context, then this error will not occur.
See the following script as example for your workaround:

// this will fail
var refrnce = new SomeOtherClass();
var obj = new SomeClass(){ Id = 123, Reference = refrnce };
ctx.Add(obj) // will fail
 
// this will not fail
var obj = new SomeClass(){ Id = 123 };
ctx.Add(obj) // will not fail
var refrnce = new SomeOtherClass();
obj.Reference = refrnce;

Please accept my apologies for any inconvenience caused.
I hope this information is helpful for you.
Feel free to ask if you have any other question.
 All the best,
Ralph
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Adrian
Top achievements
Rank 2
answered on 03 Sep 2012, 09:20 AM
Hello
I am the same problem.I think it is a problem in OpenAccess.
If you have 1 class with releation 1:n
and in your code is like this:
 Achitare.FmTipDocumente = model.FmTipuriDocumentes.Where(p => p.NumeScurt == "CHIT").FirstOrDefault();
Openaccess generate this error when you add this object to model.
One temporary solution for you is this:
 Achitare.FkTipDocumente = (model.FmTipuriDocumentes.Where(p => p.NumeScurt == "CHIT").FirstOrDefault()).Pk;
0
Eloy Paredes
Top achievements
Rank 1
answered on 03 Sep 2012, 04:25 PM
Thanks for the replay.

Now we just wait for the next version.

as my code is somewhat complicated by the changes you pose I get another error.
0
Ralph Waldenmaier
Telerik team
answered on 04 Sep 2012, 12:08 PM
Hello Eloy Paredes,

The next version will have the needed bits to work with the approach you had before.

@Neagoe: Have you tried to set your references when your object is managed by the context? You shouldn't get an error then as described earlier.

Do come back if you need further assistance.

Regards,
Ralph
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Ian
Top achievements
Rank 1
answered on 16 Sep 2012, 09:50 PM
Hi,
This error is killing us. Is there an internal build available with the fix in it?
ian
0
Ralph Waldenmaier
Telerik team
answered on 17 Sep 2012, 08:42 AM
Hi Ian,

The bug is already fixed and will be available with the next internal build to be released soon. I will keep you updated once the internal build is released.

Please accept my apologies for the inconvenience caused so far.

Regards,
Ralph
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Myth
Top achievements
Rank 1
answered on 21 Sep 2012, 07:22 AM
Any update on when the next internal update will be released? I'm also troubled by this bug so I removed the new version and reinstalled my previous.
0
Ralph Waldenmaier
Telerik team
answered on 21 Sep 2012, 08:12 AM
Hi Myth,

The new build will be available soon. Most probably in a few days.
I will keep you updated as soon as the update is released.

Kind regards,
Ralph
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Mirco
Top achievements
Rank 1
answered on 24 Sep 2012, 03:16 PM
Hello Ralph,
same issue here: I have an object (let's say "order") with a classic foreing key reference (let's say "customer").
"customer" is a non nullable external reference.

I get the exception as soon as I add the "order" to the context using code below:

Order newOrder = new Order();
newOrder.Customer = GetCustomer("customerCode");
model.OpenAccessContext.add(newOrder);

We are in great hurry here ... 

thanks

PS I noticed an inconsistency in the OrmModel (.rlinq) file. There's a non-nullable field that is actually missing from the actual Class and from the database table. Updating the model from the database doesn't fix that.


PPS NOW SOLVED
ok I got it.
FIRST I have to create the "order" object WITHOUT any reference to the CUSTOMER. 
Then I have to add the ORDER to the Context
Then I have to load the CUSTOMER from the context
Then I have to add the ORDER to the CUSTOMERS.ORDERS collection

Probably I were missing the IsManaged property of the relation in the designer
0
Ralph Waldenmaier
Telerik team
answered on 24 Sep 2012, 06:50 PM
Hello Mirco,

the issue has been fixed with the latest internal build which is available for download since today.
I hope your issue has been solved.

Do come back if you have further questions. 

Greetings,
Ralph
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!
0
Vinicius
Top achievements
Rank 1
answered on 13 Oct 2012, 05:20 PM
what´s link of the download?
0
Ivailo
Telerik team
answered on 18 Oct 2012, 01:41 PM
Hi,

I would suggest you to directly download the Q3 2012 release of OpenAccess ORM which is now available on our site. You can access it either by Your Account -> Manage Products -> Free Products -> OpenAccess ORM, or you can just go the OpenAccess homepage and download it from there.


All the best,
Ivailo
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
Data Access Free Edition
Asked by
Eloy Paredes
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Adrian
Top achievements
Rank 2
Eloy Paredes
Top achievements
Rank 1
Ian
Top achievements
Rank 1
Myth
Top achievements
Rank 1
Mirco
Top achievements
Rank 1
Vinicius
Top achievements
Rank 1
Ivailo
Telerik team
Share this question
or