Page 1 of 1

NullReferenceException occurs when quering Entity with EntitySet

Posted: Tue 24 Jun 2014 10:02
by Albert
Hello,
I try to map my entities via attribute mapping exactly as shown here http://www.devart.com/linqconnect/docs/ ... pping.html
When I try to get first Company:

Code: Select all

var c = dc.GetTable<Company>().First()
I get: "An unhandled exception of type 'System.NullReferenceException' occurred in Devart.Data.Linq.dll
Additional information: Object reference not set to an instance of an object."
with the following StackTrace:

Code: Select all

   at Devart.Data.Linq.Mapping.Accessors.EntitySetDefSourceAccessor`2.a(T A_0)
   at Devart.Data.Linq.Mapping.Accessors.MetaAccessor`2.GetBoxedValue(Object instance)
   at Devart.Data.Linq.Engine.MaterializerServices.AssignEntitySetLoader[T](a9 factory, MetaAccessor sourceAccessor, Object entity, Object[] keyValues)
   at MaterializeOrganization(MaterializerScope )
   at Devart.Data.Linq.Engine.ObjectReader`1.a()
   at Devart.Data.Linq.Engine.EntityReader`3.a()
   at Devart.Data.Linq.Engine.ObjectReader`1.a(T& 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.Table`1.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source)
   at TestDevart2.Program.Main(String[] args) in c:\Users\User1\Documents\Visual Studio 2013\Projects\TestDevart2\TestDevart2\Program.cs:line 67
   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()
But when I replace (in Company class):

Code: Select all

private EntitySet<Order> _Orders;
with:

Code: Select all

private EntitySet<Order> _Orders = new Devart.Data.Linq.EntitySet<Order>();
, the sample works fine. What could be wrong?
Thanks!

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Tue 24 Jun 2014 13:26
by MariiaI
We couldn't reproduce this issue in our environment. Please provide us with the following information:
- the version of LinqConnect;
- the DBMS you are working with;
- the definitions of the entity classes and the DDL/DML scripts for the corresponding database tables;
If possible, please send us a test project, with which the error is reproducible, so that we could investigate it in more details and find the solution for you in a shortest time.

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Wed 25 Jun 2014 10:36
by Albert
I use:
- the last version (8.4.181) dotConnect for Oracle, that includes LinqConnect v4.4.519.0
- the Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production.
I sent you a test project with the definitions of the entity classes and the DDL/DML scripts for the corresponding database tables.
Waiting for your response.
Thanks!

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Thu 26 Jun 2014 08:22
by MariiaI
We have not received the test project, please try sending it again. Also, please send it to 'mariiai at devart dot com'.
As an alternative, you can upload your project to some file exchange server and give us a download link.

Looking forward to your reply.

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Thu 26 Jun 2014 08:53
by Albert
You can download the test project from this link
https://onedrive.live.com/?cid=e2db3a53 ... xnqkQKAyf8

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Thu 26 Jun 2014 11:44
by MariiaI
Thank you for the sample project. We have reproduced the issue with it. We will investigate it in more details and inform you about the results as soon as possible.

Re: NullReferenceException occurs when quering Entity with EntitySet

Posted: Wed 02 Jul 2014 13:01
by MariiaI
We have investigated the issue in more details. This exception is expected due to the fact, that it is necessary to add the class constructor with the creation of the EntitySet and EntityRef instances for proper work. For example, you can check the code generation in Entity Developer based on the corresponding databases tables, e.g.:

Code: Select all

 public Order()
{
  this._Company = default(EntityRef<Company>);
  OnCreated();
}

 public Company()
{
  this._Orders = new EntitySet<Order>(new Action<Order>(this.attach_Orders), new Action<Order>(this.detach_Orders));
  OnCreated();     
}
In your code sample

Code: Select all

 public EntitySet<Order> Orders
    {
        get { return this._Orders; }
        set { this._Orders.Assign(value); 
    }
the Assign method is called explicitly for the "_Orders." Due to the fact that "Orders" is null, the NullReferenceException occurs.

As for the documentation, we will correct it as soon as possible.