473,403 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 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 2509
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
11
by: =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post by:
Hello, played a little with orcas and went into a problem by building dynamic queries. I want to build a dynamic where clause but only with parameters that are not empty =(TextBox.Text != "")....
15
by: EDBrian | last post by:
My problem is this. Our clients create different fields they want to collect and we allow them build dynamic filters, reports etc... We run some TSQL to actually create the column and all works...
9
by: =?Utf-8?B?RXZlcnQ=?= | last post by:
In my (Windows Forms) project I am using strongly typed datatables. Now I am trying to convert my 'rowfilter/group by' query logic to Linq. Most queries I can easily convert, but some I am having...
1
by: Lacutas | last post by:
Hi I'm having some problems getting a dynamic LINQ query to work on my DataSet. The idea is that a user selects certain criteria, and then the LINQ query filters through the dataset making the...
1
by: john | last post by:
I'm trying to build a LINQ expression that will use a dynamic construction of a LIKE statement in the WHERE clause, it would look something like this in SQL: WHERE TaskGroup Like "*00*" OR...
10
by: Jonathan | last post by:
Hi all, I have a file consisting fixed width records from which I need to extract only those lines meeting certain conditions. These conditions do change and I find myself recoding/compiling...
4
by: acgritt | last post by:
I am looking for some information on if it is possible/how to create a dynamic XLinq statement. I know for Linq to SQL you can do the following: var query = db.Customers. Where("City = @0 and...
4
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to set up a dynamic search using linq. I believe the syntax is correct, but cannot confirm it because when I try to cast my Session from a List<to IQueryable<>, I get a cast error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.