none
ArgumentNullException on Delay Loaded Property using a SQL View RRS feed

  • Question

  • I'm receiving an ArgumentNullException when trying to access a property of an object when that property is set to Delay Loaded = true.  If I set delay loaded = false I'm able to access the property without any exceptions.

    It appears to be related to tying a Linq to Sql object to a Sql View.  When I try to access any property tied a Sql View that is set to delay loaded = true I get an ArgumentNullException.

    As a test I used the adventure works db.  I created a view from the documents table with all of the columns selected.  If I set any property to delay loaded = true I get the exception.  I then used the Sql table itself in the linq to sql diagram and I didn't have any issues.  I was able to set delay loaded = true using the object tied to the Sql table.

    Is Delay Loaded on SQL Views supported?  Am I doing something wrong?

    VS 2008 SP1

    .Net 3.5 SP1


    Regards, Mike DePouw
    Friday, January 28, 2011 9:20 PM

Answers

  • Hi Alan, thanks for the reply.

    I'm not seeing the results you described.  Delay loaded = true does work when it comes to the SQL generation.  It doesn't seem to work when I access that property later on.

    Your post did get me thinking and I solved my issue, set the primary key on the View!  I set the primary key in my diagram and all is well now!  Thanks for you assistance.

    I blogged the exception and how to fix here.


    Regards, Mike DePouw
    • Marked as answer by Mike DePouw Monday, January 31, 2011 2:56 PM
    Monday, January 31, 2011 2:56 PM

All replies

  • Hi Mike,

    Thanks for your post.

    According to your description, I reapeared your scenario and got the same exception, let's look the t-sql differernt between the two scenario:

    using (var context1 = new DataClasses1DataContext())
       {
        var x = from c1 in context1.testviews select c1;//view 
        var cust = from c2 in context1.Customers select c2;//table 
       }
    // there are the same structure ---CustomerId set delay loaded= true
    {SELECT [t0].[CustomerName] FROM [dbo].[testview] AS [t0]}
    
    {SELECT [t0].[CustomerId], [t0].[CustomerName] FROM [dbo].[Customers] AS [t0]}
    

    The view doesn't select the CustomerId.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 31, 2011 8:47 AM
    Moderator
  • would it make a differnece if the view was bound to the database schema ??
    That would allow use of indexes, which is quiet important when using lazy loading.

     

    Just a thought though;;;

    Monday, January 31, 2011 9:27 AM
  • Hi Alan, thanks for the reply.

    I'm not seeing the results you described.  Delay loaded = true does work when it comes to the SQL generation.  It doesn't seem to work when I access that property later on.

    Your post did get me thinking and I solved my issue, set the primary key on the View!  I set the primary key in my diagram and all is well now!  Thanks for you assistance.

    I blogged the exception and how to fix here.


    Regards, Mike DePouw
    • Marked as answer by Mike DePouw Monday, January 31, 2011 2:56 PM
    Monday, January 31, 2011 2:56 PM
  • Hi Mike,

     I’m glad to hear that you got it working. Thank you for sharing your experience here.

    It will be very beneficial for other community members having the similar questions.

     

    By the way, I am sorry about my wrong direction.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 1, 2011 12:52 AM
    Moderator