473,790 Members | 2,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: convert query to DLinq

In the same spirit, but more LINQ related, you can also use ExecuteQuery:
var query = dataContext.Exe cuteQuery<class Name>( @"SELECT ... WHERE ...
AND... OR... ");
where className is appropriate to recuperate the result of your dynamically
built SQL statement, as a string.


Vanderghast, Access MVP

Jul 2 '08 #1
1 2189
Application creates business part of query dynamically using commands like

if (!string.IsNull OrEmpty( Param.CustName ) )
q = q.Where( c=c.CustomerNam e==Param.CustNa me );

if (!string.IsNull OrEmpty( Param.CustCity ) )
q = q.Where( c=c.City==Param .CustCity );

I do'nt know a way to get generated sql as string.
So this approach requires to use string builder instead of this. Large parts
of application should use string concatenation to build business-logic
queries instead of DLinq.

I'm not sure is this good solution. So I'm searching for a way to create
extension method

IQueryable<TLes sThanOrEqual<T> ( IQueryable<Tthi s, string c1, string c2,
object v1, object2, Type v1Type, Type v2Type )

or in general form

IQueryable<TLes sThanOrEqual<T> ( IQueryable<Tthi s, string[] propertyName,
object[] propertyValue, Type[] propertyValueTy pe)

which generates comparison query (c1,c2) <= (v1,v2)

I created single property extension method below but don't know how to
change it to use two properties.

Andrus.

// creates property <= value query.
public static IQueryable<TLes sThanOrEqual<T> (this IQueryable<Tsou rce,
string property, object value, Type propertyType)
{
ParameterExpres sion param = Expression.Para meter(typeof(T) ,
"x");
Expression val;
val = Expression.Cons tant(value, propertyType);
Expression prop = Expression.Prop erty(param, property);
BinaryExpressio n testExp = null;
if (propertyType == typeof(string))
{
Expression call = Expression.Call (
typeof(Microsof t.VisualBasic.C ompilerServices .Operators).Get Method("Compare String",
new[] { typeof(string), typeof(string), typeof(bool) }),
prop, val,
Expression.Cons tant(false, typeof(bool)));
testExp = LambdaExpressio n.LessThan(call ,
Expression.Cons tant(1, typeof(int)));
}
else
{
testExp = LambdaExpressio n.LessThanOrEqu al(prop, val);
}
return source.Where(Ex pression.Lambda <Func<T, bool>>(testExp,
param));
}
"Michel Walsh" <va************ *************@n ospam.comwrote in message
news:FD******** *************** ***********@mic rosoft.com...
In the same spirit, but more LINQ related, you can also use ExecuteQuery:
var query = dataContext.Exe cuteQuery<class Name>( @"SELECT ... WHERE
... AND... OR... ");
where className is appropriate to recuperate the result of your
dynamically built SQL statement, as a string.


Vanderghast, Access MVP
Jul 3 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2958
by: John Scott | last post by:
Ok...here we go... I am trying to manually run an SQL server back up job from c#. Here is a snippet of my code to begin the process: string strSQL = "USE msdb " + "\n if exists(select * from sysjobs_view where name = 'TempBackupJob') " + "\n EXEC sp_delete_job @job_name = 'TempBackupJob' " + "\n GO"; newDB.Command(strSQL);
2
15865
by: Bubba | last post by:
I know it's possible, just don't know how to do it. I have a spreadsheet that I imported into access. Two of the columns in the table have Hard Drive space values listed for example 2.45 GB and 453 MB, you get the picture. Both the GB and MB assorted values exist in both columns. Is there anyway to convert the GB or MB to 0's, or even better yet decimal places so I can look for values < or > to 6gb. I already tried a query, but it seems...
7
1868
by: Senna | last post by:
Hi Have a question about DLinq. The example code floating around looks like this: Northwind db = new Northwind(@"C:\...\northwnd.mdf"); var custs = from c in db.Customers where c.City == "London" select c; How does this work. Will it retreive all the rows from the Customer table
0
979
by: Andrus | last post by:
I need to update natural primary key like Territories.TerritoryID column in northwind database. In pure ADO .NET this is easy. I can use ExecScalar to run UPDATE command on primary key. Server referential integrity causes cascade updates automatically. I read from MSDN that Linq-SQL does not allow to update object ids.
0
1287
by: Andrus | last post by:
How to create select columns list dynamically in DLinq ? I want to create something like Console.WriteLine("Enter list of columns to return, separated by commas:"); string list = Console.ReadLine(); var q = from c in Db.Customers where c.Location=="London" select list;
19
1529
by: Andrus | last post by:
I need to repeatedly execute same queries which returns single entity by id, like: Customer cust = (from c in db.Customers where c.CustomerID=="AIRBU" select c).SingleOrDefault(); DLinq holds tracked object list internally so customer "AIRBU" exists in memory.
9
1688
by: Marc Gravell | last post by:
How to fix ? Write it the way that you know works... (i.e. the one you commented out), or write that parses the input string doing a Split on '.', and uses reflection to navigate the child hierarchy. Which isn't something I have time to do right now... Marc
11
3559
by: Andrus | last post by:
I created dynamic extension methods for <= and < SQL comparison operators: public static IQueryable<TLessThanOrEqual<T>(this IQueryable<Tsource, string property, object value); public static IQueryable<TLessThan<T>(this IQueryable<Tsource, string property, object value); For example var q = db.Customers.LessThanOrEqual( "City", "London" );
4
2456
by: Andrus | last post by:
DLinq objects: class Item { string ItemCode {get;set;} // primary key } class Stock { // primary key is (ItemCode,StockId) string ItemCode {get;set;} string Quantity { get; set; } string StockId { get; set; }
0
9666
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10200
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...
0
9986
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9021
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
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
5422
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...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4094
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
2
3707
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.