Page 1 of 1

Exception on loading deep nested entities

Posted: Tue 14 Jul 2015 20:45
by shedar
I use LinqConnect with SQLite database.
I have following relations Freight => Firm => FirmContacts.
It works fine on selecting of entities and entities with child entities. So I can select Freight and Freight with Firm. But it throws an exception When I execute following query

Code: Select all

_db.Freights.LoadWith("Firm.FirmContacts").Where(x => x.AccId == _accId && x.Id == 4).FirstOrDefault();
So I can't load Freight with Firm and FirmContacts.
I tried with other entities with no luck. Problem always occurs on same level of nesting.
Exception:

Code: Select all

  
Unable to cast object of type 'System.Byte[]' to type 'System.String'.

 at Devart.Data.Linq.Engine.ObjectReader`1.CacheStorageReader.GetString(Int32 i)
   at MaterializeRoundtrip(MaterializerScope )
   at Devart.Data.Linq.Engine.JoinedEntityReader`3.a(Object A_0, TKey& A_1)
   at Devart.Data.Linq.Engine.JoinedEntityReader`3.a(TEntity& A_0)
   at Devart.Data.Linq.Engine.ObjectReader`1.c()
   at Devart.Data.Linq.DataProvider.a(c1 A_0, IDbConnection A_1, IDataReader A_2)
   at Devart.Data.Linq.DataProvider.a(c1 A_0, Object[] A_1)
   at Devart.Data.Linq.DataProvider.c(Expression A_0)
   at Devart.Data.Linq.Engine.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)

Re: Exception on loading deep nested entities

Posted: Wed 15 Jul 2015 10:02
by MariiaI
We couldn't reproduce this issue. Please describe your scenario in more details, so that we are able to further investigate the issue. For example, provide us with the following details:
- the version of LinqConnect;
- the definitions of the DataContext class and entity classes, etc.

If possible, please send us a small test project with the corresponding DDL/DML scripts (or test database), with which this issue is reproducible. This will significantly speed up the process of determining the cause of the error and finding the solution for it.

Looking forward to your reply.

Re: Exception on loading deep nested entities

Posted: Wed 15 Jul 2015 10:44
by shedar
I sent you an email with demo project to reproduce this issue.

- version of LinqConnect 4.4.785.0
- definitions can be found in demo project.

Re: Exception on loading deep nested entities

Posted: Thu 16 Jul 2015 10:38
by MariiaI
Thank you for the test project. We have investigated it.
The issue is in the fact that:
- the Note column (in the Freight and Firm tables) has the 'Blob SubType Text' data type and the text data is stored there;
- the corresponding entity properties (in the Freight and FirmSummary entity classes) are mapped to System.String data type and while retrieving data from these tables the mentioned error occurs, because LinqConnect doesn't treat BLOBs as text.

We recommend you to change the data type of the Note column from 'Blob SubType Text' to 'Text'/'NText' in the necessary database tables.

Please notify us about the results.

Re: Exception on loading deep nested entities

Posted: Thu 16 Jul 2015 13:07
by shedar
Thanks a lot for your help!

It works like a charm.

I wasn't even looking at those fields, because entities loading worked without error until I added loading of child entities.

Re: Exception on loading deep nested entities

Posted: Thu 16 Jul 2015 13:26
by MariiaI
Glad to see that the issue was resolved.
If you have any further questions, feel free to contact us.