473,693 Members | 3,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Dyn amic;
using System.Data.Lin q;
....
string connString = @"Data Source=.;Initia l
Catalog=Northwi nd;Integrated Security=True";
DataClasses1Dat aContext db = new
DataClasses1Dat aContext(connSt ring);
....
private void only_exp_query( )
{

Table<Customer_ customer = db.Customers;
var query = db.Customers
.Where("City=@0 ", "LONDON")
.OrderBy("Compa nyName");
dataGridView1.D ataSource = query;
}

private void only_tbl_query( )
{
Table<Customer_ customer = db.Customers;

var query = from tbl in _customer
select tbl;
dataGridView1.D ataSource = 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("Cust omers")
.Where("City=@0 ", "LONDON")
.OrderBy("Compa nyName");
dataGridView1.D ataSource = query;
}

and then i can try this below script...

private void full_query()
{
Assembly asm =
Assembly.GetAss embly(typeof(Da taClasses1DataC ontext));

var query = db.GetTable(asm .GetType("Custo mer"));
.Where("City == @0 and Orders.Count >= @1", "London", 10)
.OrderBy("Compa nyName, City")
.Select("New(Co mpanyName as Name, Phone)");
dataGridView1.D ataSource = query;
}
but it returns the following error:
"ArgumentNullEx ception 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 2523
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.GetAss embly(typeof(Da taClasses1DataC ontext));
var query = db.GetTable(asm .GetType("Custo mer"));

we change this row
Table<Customer_ customer = this.Context.Ge tTable( typeof(Customer ) ) as
Table<Customer> ;"Mucahit ikiz" <mu**********@s ifas.com.trwrot e in message
news:%2******** ********@TK2MSF TNGP06.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.Dyn amic;
using System.Data.Lin q;
...
string connString = @"Data Source=.;Initia l
Catalog=Northwi nd;Integrated Security=True";
DataClasses1Dat aContext db = new
DataClasses1Dat aContext(connSt ring);
...
private void only_exp_query( )
{

Table<Customer_ customer = db.Customers;
var query = db.Customers
.Where("City=@0 ", "LONDON")
.OrderBy("Compa nyName");
dataGridView1.D ataSource = query;
}

private void only_tbl_query( )
{
Table<Customer_ customer = db.Customers;

var query = from tbl in _customer
select tbl;
dataGridView1.D ataSource = 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("Cust omers")
.Where("City=@0 ", "LONDON")
.OrderBy("Compa nyName");
dataGridView1.D ataSource = query;
}

and then i can try this below script...

private void full_query()
{
Assembly asm =
Assembly.GetAss embly(typeof(Da taClasses1DataC ontext));

var query = db.GetTable(asm .GetType("Custo mer"));
.Where("City == @0 and Orders.Count >= @1", "London", 10)
.OrderBy("Compa nyName, City")
.Select("New(Co mpanyName as Name, Phone)");
dataGridView1.D ataSource = query;
}
but it returns the following error:
"ArgumentNullEx ception 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
3021
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 proper tier to put it since is a data function But then I've heard that writing SQL in my client .NET code might run just as fast? Dynamic SQL or something? And then there's LINQ on the horizon. Is it a successor to everything
11
13662
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 != ""). Doing this by building a string is very simple, but how to do it with LINQ? string sql = ""; if (TextBox1.Text != "") sql += "Columns_1='"+TextBox1.Text+"'"; if (TextBox2.Text != "")
15
10855
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 very well. We are now adding a lot more functionality to our filters and could really benefit from using the LINQ to SQL. I have experimented with the Dynamic Linq...
9
14051
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 difficulties with: the ones dynamic in nature. I solved it (temporary) by copy-pasting static queries. This is not an ideal solution because now my code contains some duplicate code. Some of the problems I have are: - My select statements...
1
6986
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 requested changes. The table I am trying to alter is called RawData, this is defined in a DataSet but has no data columns as these aren't known until some data is imported. As part of my import routine it automatically creates the correct columns...
1
3743
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 TaskGroup Like "*20*" It would be many variations on the above.
10
2800
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 for each set of conditions then running again. e.g.
4
2744
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 Orders.Count >= @1", "London", 10). OrderBy("CompanyName"). Select("new(CompanyName as Name, Phone)"); I am wondering how to do this with Linq to XML. I know I can do the
4
3597
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 “Unable to cast object of type System.Collections.Generic.List to type System.Linq.IQueryable”. Is there a way to cast List<to IQueryable<>, or is there a different way I need to be doing this? protected void btnSearch_Click(object sender,...
0
8616
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9105
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8971
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8816
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6477
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5825
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4332
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2990
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.