471,616 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

I cant make a full dynamic query in LINQ


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(DataClasses1DataContex t));

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
Jul 7 '08 #1
2 2415
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
Jul 8 '08 #2
This problem was solve.

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

we change this row
Table<Customer_customer = this.Context.GetTable( typeof(Customer) ) as
Table<Customer>;"Mucahit ikiz" <mu**********@sifas.com.trwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>
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(DataClasses1DataContex t));

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

Jul 8 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Ronald S. Cook | last post: by
11 posts views Thread by =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post: by
15 posts views Thread by EDBrian | last post: by
9 posts views Thread by =?Utf-8?B?RXZlcnQ=?= | last post: by
1 post views Thread by Lacutas | last post: by
1 post views Thread by john | last post: by
4 posts views Thread by acgritt | last post: by
4 posts views Thread by =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.