PC Review


Reply
Thread Tools Rate Thread

I cant make a full dynamic query in LINQ

 
 
Mucahit ikiz
Guest
Posts: n/a
 
      7th Jul 2008

I cant make a full dynamic query in LINQ

I have 2 situation methods (only_exp_query, only_tbl_query) those are
working.

....
using System.Linq.Dynamic;
using System.Data.Linq;
....
string connString = @"Data Source=.;Initial
Catalog=Northwind;Integrated Security=True";
DataClasses1DataContext db = new
DataClasses1DataContext(connString);
....
private void only_exp_query()
{

Table<Customer> _customer = db.Customers;
var query = db.Customers
.Where("City=@0", "LONDON")
.OrderBy("CompanyName");
dataGridView1.DataSource = query;
}

private void only_tbl_query()
{
Table<Customer> _customer = db.Customers;

var query = from tbl in _customer
select tbl;
dataGridView1.DataSource = query;
}


But i want to run the script below , but it is not working...

private void full_query()
{

Table<Customer> _customer = db.Customers;
var query = db.Customers
.GetTable("Customers")
.Where("City=@0", "LONDON")
.OrderBy("CompanyName");
dataGridView1.DataSource = query;
}

and then i can try this below script...

private void full_query()
{
Assembly asm =
Assembly.GetAssembly(typeof(DataClasses1DataContext));

var query = db.GetTable(asm.GetType("Customer"));
.Where("City == @0 and Orders.Count >= @1", "London", 10)
.OrderBy("CompanyName, City")
.Select("New(CompanyName as Name, Phone)");
dataGridView1.DataSource = query;
}
but it returns the following error:
"ArgumentNullException was unhandled ,Value Cannot be null,Parameter Type"
but i dont know this error.


WHAT CAN I DO?
can you help me please


 
Reply With Quote
 
 
 
 
Marc Gravell
Guest
Posts: n/a
 
      8th Jul 2008
First thought; one of the primary aims of LINQ is to provide things
like compile-time checking to expressions, and a better development
experience. By going down a fully dynamic route, you're not really
getting many of those benefits... so an I ask (out of curiosity) why
regular LINQ isn't an option here? There may be better ways of doing
what you want.

Marc
 
Reply With Quote
 
Mucahit ikiz
Guest
Posts: n/a
 
      8th Jul 2008
This problem was solve.

that
Assembly asm = Assembly.GetAssembly(typeof(DataClasses1DataContext));
var query = db.GetTable(asm.GetType("Customer"));

we change this row
Table<Customer> _customer = this.Context.GetTable( typeof(Customer) ) as
Table<Customer>;"Mucahit ikiz" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>
> I cant make a full dynamic query in LINQ
>
> I have 2 situation methods (only_exp_query, only_tbl_query) those are
> working.
>
> ...
> using System.Linq.Dynamic;
> using System.Data.Linq;
> ...
> string connString = @"Data Source=.;Initial
> Catalog=Northwind;Integrated Security=True";
> DataClasses1DataContext db = new
> DataClasses1DataContext(connString);
> ...
> private void only_exp_query()
> {
>
> Table<Customer> _customer = db.Customers;
> var query = db.Customers
> .Where("City=@0", "LONDON")
> .OrderBy("CompanyName");
> dataGridView1.DataSource = query;
> }
>
> private void only_tbl_query()
> {
> Table<Customer> _customer = db.Customers;
>
> var query = from tbl in _customer
> select tbl;
> dataGridView1.DataSource = query;
> }
>
>
> But i want to run the script below , but it is not working...
>
> private void full_query()
> {
>
> Table<Customer> _customer = db.Customers;
> var query = db.Customers
> .GetTable("Customers")
> .Where("City=@0", "LONDON")
> .OrderBy("CompanyName");
> dataGridView1.DataSource = query;
> }
>
> and then i can try this below script...
>
> private void full_query()
> {
> Assembly asm =
> Assembly.GetAssembly(typeof(DataClasses1DataContext));
>
> var query = db.GetTable(asm.GetType("Customer"));
> .Where("City == @0 and Orders.Count >= @1", "London", 10)
> .OrderBy("CompanyName, City")
> .Select("New(CompanyName as Name, Phone)");
> dataGridView1.DataSource = query;
> }
> but it returns the following error:
> "ArgumentNullException was unhandled ,Value Cannot be null,Parameter Type"
> but i dont know this error.
>
>
> WHAT CAN I DO?
> can you help me please
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
populate a DataSet via a LINQ query (Linq to XML) Anthony Microsoft C# .NET 12 19th Apr 2010 06:49 AM
Linq to XML--Are there code examples that make Linq as easy as SQL? Or how can I convert ths simple pseudo code into real code? Reece Microsoft C# .NET 4 10th Dec 2008 03:13 AM
Linq to SQL - Return DataTable as a result of Linq query szwejk Microsoft C# .NET 3 1st Feb 2008 03:07 PM
LINQ: How to build dynamic query? =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= Microsoft C# .NET 39 20th Nov 2007 04:00 PM
How do I make a query with dynamic number of coloumns? Ebbe Microsoft Access 8 27th Dec 2004 05:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:55 AM.