May have spoken (? written/emailed) too soon.

 

You can use a custom linq query expression with a linqDatasource

http://weblogs.asp.net/scottgu/archive/2007/09/07/linq-to-sql-part-9-using-a
-custom-linq-expression-with-the-lt-asp-linqdatasource-gt-control.aspx

 

I think that if your query returns anything other than what is available on
your Linq to sql classes (  .dbml item) i.e. a custom projection, you will
need to handle all the crud stuff yourself.

I am going to have to experiment with this to be certain it will work.

See
http://weblogs.asp.net/scottgu/archive/2007/08/23/linq-to-sql-part-7-updatin
g-our-database-using-stored-procedures.aspx

 

You have to use events to take back control.

 

You need to do this to generate a datacontext that uses a different database
connection string as well.

http://stackoverflow.com/questions/1188962/linq-to-sql-set-connection-string
-dynamically-based-on-environment-variable

 

Anyway I think I have enough to work with now. I just got to get on with it.

 

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 Peter Maddin
Sent: Friday, 30 March 2012 3:30 PM
To: 'ozDotNet'
Subject: RE: Dynamically binding a linq query to a linqdatasource

 

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.

 

 

 

Reply via email to