Hi Michael
This how I expected it to work. But the LinqDataSource has no DataSource property. You have to use ContextTypeName and TableName which are string properties . All in all a bit of an anticlimax. I was expecting to construct LINQ queries and bind them. The LinqDataSource handles it for you. As far as I understand it If you want to do use your own linq queries you would need to project this to a bindable collection and then handle all crud events on the ViewGrid yourself via the datacontext. In this case you would bypass the linqdatasource. I suppose this is a better pattern to adopt to have a separation of concerns. I am looking forward to your asp.net MVC 4 presentation in anycase. Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 6396 4285 (Monday, Wednesday,Friday) Phone : +618 9346 4372 (Tuesday, Thursday) Mobile: 0423 540 825 E-Mail : [email protected]; [email protected] The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately. From: [email protected] [mailto:[email protected]] On Behalf Of Michael Minutillo Sent: Friday, 30 March 2012 2:28 PM To: ozDotNet Subject: Re: Dynamically binding a linq query to a linqdatasource Because LINQ is lazily evaluated you can build up a query and never go to the database (until you enumerate it anyway). So you can probably do something like this: var products = db.Products; if(!showDiscontinued) { products = products.Where(x => x.IsDiscontinued == false); } // many more clauses and filters // Up until now no database requests have been made LinqDataSource.DataSource = products; // When the LinqDataSource enumerates the products object the query will be executed. Michael M. Minutillo Indiscriminate Information Sponge http://codermike.com On Fri, Mar 30, 2012 at 2:14 PM, Peter Maddin <[email protected]> wrote: Looks like the linqdatasource generates the linq for you. You just have to use the properties like select and where, before you bind the linqdatasource to your viewgrid. I feel like this sorts of defeats learning linq to some degree. Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 6396 4285 <tel:%2B618%206396%204285> (Monday, Wednesday,Friday) Phone : +618 9346 4372 <tel:%2B618%209346%204372> (Tuesday, Thursday) Mobile: 0423 540 825 E-Mail : [email protected]; [email protected] The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately. From: [email protected] [mailto:[email protected]] On Behalf Of Peter Maddin Sent: Friday, 30 March 2012 1:39 PM To: [email protected] Subject: Dynamically binding a linq query to a linqdatasource I want to use linqtosql to do crud. I want to bind a viewgrid to a linqdatasource which is bound to a datacontext. If you want to do this for every row in the table that is easy. I want to dynamically build a linq query to return a subset of rows that I can manipulate and update within the viewgrid and then apply the changes back to the database. The linqdatasource requires a contexttypename and then a table name. Is it possible to build a dynamic linq query i.e. get all customers that are in Victoria and have a debt less than $1000 and bind this via the linqdatasource to my ViewGrid. I can then update records via the ViewGrid and then submit these back using the datacontext. I would seem this would be a fairly common requirement. All my information on LINQ requires me to wade through pages of how to dump stuff to the console or do really simple binding. Regards Peter Maddin Applications Development Officer PathWest Laboratory Medicine WA Phone : +618 6396 4285 <tel:%2B618%206396%204285> (Monday, Wednesday,Friday) Phone : +618 9346 4372 <tel:%2B618%209346%204372> (Tuesday, Thursday) Mobile: 0423 540 825 E-Mail : [email protected]; [email protected] The contents of this e-mail transmission outside of the WAGHS network are intended solely for the named recipient's), may be confidential, and may be privileged or otherwise protected from disclosure in the public interest. The use, reproduction, disclosure or distribution of the contents of this e-mail transmission by any person other than the named recipient(s) is prohibited. If you are not a named recipient please notify the sender immediately.
