Linq data source selecting and sort

Discussion in 'ASP .Net Web Controls' started by Chuck, Feb 11, 2010.

  1. Chuck

    Chuck Guest

    I have a grid with a LinqDataSource.
    In the linqdatasource.selecting event I
    use e.Result =( a linq query).
    I do this because I have one aspx page where I return a query with different
    columns based on what the user wants to see. The grid has autocolumns
    selected. Thus I change the columns and query at runtime.

    The problem I have is if I enable sorting, I get an exception if I change
    the linq query to one with different columns after a postback.

    Essentially in the LinqDataSource1_Selecting LinqDataSourceSelectEventArgs e
    e.Arguments.sort.expression has a value that contains a column that is not
    in the new linq query and it barfs.

    Is there a way to clear this value on a postback.
    I tried reseting the Grids datasource and nulling the LinqDataSource, but
    nothing worked.
    Chuck, Feb 11, 2010
    #1
    1. Advertising

  2. Hi,
    What's error you got if you change the Linq query to one with different
    colums after postback?

    Why you need reset the LinqDatasource? It sounds you had better build a
    Datasource object by Linq dynamically, don't you?

    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-
    the-linq-dynamic-query-library.aspx

    Does that make sense?

    --
    Sincerely,

    Vince Xu

    Microsoft Online Support


    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    MSDN Managed Newsgroup support offering is for non-urgent issues where an
    initial response from the community or a Microsoft Support Engineer within
    2 business day is acceptable. Please note that each follow up response may
    take approximately 2 business days as the support professional working with
    you may need further investigation to reach the most efficient resolution.
    The offering is not appropriate for situations that require urgent,
    real-time or phone-based interactions. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    --------------------
    | Thread-Topic: Linq data source selecting and sort
    | thread-index: AcqrZ8sXkM7ZlmAIRzCZYN5crffNug==
    | X-WBNR-Posting-Host: 192.12.184.2
    | From: Chuck <>
    | Subject: Linq data source selecting and sort
    | Date: Thu, 11 Feb 2010 14:16:01 -0800
    | Lines: 19
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Path: TK2MSFTNGHUB02.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:5080
    | NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    |
    | I have a grid with a LinqDataSource.
    | In the linqdatasource.selecting event I
    | use e.Result =( a linq query).
    | I do this because I have one aspx page where I return a query with
    different
    | columns based on what the user wants to see. The grid has autocolumns
    | selected. Thus I change the columns and query at runtime.
    |
    | The problem I have is if I enable sorting, I get an exception if I change
    | the linq query to one with different columns after a postback.
    |
    | Essentially in the LinqDataSource1_Selecting
    LinqDataSourceSelectEventArgs e
    | e.Arguments.sort.expression has a value that contains a column that is
    not
    | in the new linq query and it barfs.
    |
    | Is there a way to clear this value on a postback.
    | I tried reseting the Grids datasource and nulling the LinqDataSource, but
    | nothing worked.
    |
    |
    |
    Vince Xu [MSFT], Feb 12, 2010
    #2
    1. Advertising

  3. Hi,

    Since I didn't get your response. Is that helpful for you?
    --
    Sincerely,

    Vince Xu

    Microsoft Online Support

    --------------------
    | X-Tomcat-ID: 75046067
    | References: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (Vince Xu [MSFT])
    | Organization: Microsoft
    | Date: Fri, 12 Feb 2010 06:57:41 GMT
    | Subject: RE: Linq data source selecting and sort
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Message-ID: <>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | Lines: 82
    | Path: TK2MSFTNGHUB02.phx.gbl
    | Xref: TK2MSFTNGHUB02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.webcontrols:5081
    | NNTP-Posting-Host: tk2tomimport1.phx.gbl 10.230.18.247
    |
    | Hi,
    | What's error you got if you change the Linq query to one with different
    | colums after postback?
    |
    | Why you need reset the LinqDatasource? It sounds you had better build a
    | Datasource object by Linq dynamically, don't you?
    |
    |
    http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-
    | the-linq-dynamic-query-library.aspx
    |
    | Does that make sense?
    |
    | --
    | Sincerely,
    |
    | Vince Xu
    |
    | Microsoft Online Support
    |
    |
    | ==================================================
    | Get notification to my posts through email? Please refer to
    | http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.
    |
    | MSDN Managed Newsgroup support offering is for non-urgent issues where an
    | initial response from the community or a Microsoft Support Engineer
    within
    | 2 business day is acceptable. Please note that each follow up response
    may
    | take approximately 2 business days as the support professional working
    with
    | you may need further investigation to reach the most efficient
    resolution.
    | The offering is not appropriate for situations that require urgent,
    | real-time or phone-based interactions. Issues of this nature are best
    | handled working with a dedicated Microsoft Support Engineer by contacting
    | Microsoft Customer Support Services (CSS) at
    | http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    | ==================================================
    | --------------------
    | | Thread-Topic: Linq data source selecting and sort
    | | thread-index: AcqrZ8sXkM7ZlmAIRzCZYN5crffNug==
    | | X-WBNR-Posting-Host: 192.12.184.2
    | | From: Chuck <>
    | | Subject: Linq data source selecting and sort
    | | Date: Thu, 11 Feb 2010 14:16:01 -0800
    | | Lines: 19
    | | Message-ID: <>
    | | MIME-Version: 1.0
    | | Content-Type: text/plain;
    | | charset="Utf-8"
    | | Content-Transfer-Encoding: 7bit
    | | X-Newsreader: Microsoft CDO for Windows 2000
    | | Content-Class: urn:content-classes:message
    | | Importance: normal
    | | Priority: normal
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontrols
    | | Path: TK2MSFTNGHUB02.phx.gbl
    | | Xref: TK2MSFTNGHUB02.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.webcontrols:5080
    | | NNTP-Posting-Host: tk2msftibfm01.phx.gbl 10.40.244.149
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontrols
    | |
    | | I have a grid with a LinqDataSource.
    | | In the linqdatasource.selecting event I
    | | use e.Result =( a linq query).
    | | I do this because I have one aspx page where I return a query with
    | different
    | | columns based on what the user wants to see. The grid has autocolumns
    | | selected. Thus I change the columns and query at runtime.
    | |
    | | The problem I have is if I enable sorting, I get an exception if I
    change
    | | the linq query to one with different columns after a postback.
    | |
    | | Essentially in the LinqDataSource1_Selecting
    | LinqDataSourceSelectEventArgs e
    | | e.Arguments.sort.expression has a value that contains a column that is
    | not
    | | in the new linq query and it barfs.
    | |
    | | Is there a way to clear this value on a postback.
    | | I tried reseting the Grids datasource and nulling the LinqDataSource,
    but
    | | nothing worked.
    | |
    | |
    | |
    |
    |
    Vince Xu [MSFT], Feb 16, 2010
    #3
  4. Chuck

    Chuck Guest

    The error is column not found because the column is not their anymore.
    You can do dyanmic queries but if you omit a column then somewhere the
    datasource is remembering the sort and tries to append the now missing coumn
    to the query and it produces the error message.

    Sorry for the late response, every month or two my notifications to
    responses on the forums and newsgroups stop.
    Chuck, Feb 26, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike N.
    Replies:
    0
    Views:
    497
    Mike N.
    Jul 31, 2008
  2. Mike N.
    Replies:
    0
    Views:
    637
    Mike N.
    Jul 31, 2008
  3. George

    Linq or not Linq

    George, Nov 4, 2008, in forum: ASP .Net
    Replies:
    4
    Views:
    356
    Mike Gleason jr Couturier
    Nov 5, 2008
  4. Ryan Liu
    Replies:
    0
    Views:
    127
    Ryan Liu
    Dec 12, 2008
  5. Navin
    Replies:
    1
    Views:
    685
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page