Ah, that makes it a bit easier! :-)
On Aug 25, 1:31 pm, "Andrus Moor" <[email protected]> wrote: > Look into DynamicLinqTest.cs for samples: > > public void DL1_Products() > { > Northwind db = CreateDB(); > > var q = db.Products.Where("SupplierID=1 And UnitsInStock>2") > .OrderBy("ProductID"); > var list = q.ToList(); > Assert.IsTrue(list.Count > 0, "Expected results from dynamic > query"); > } > > [Test] > public void DL2_ProductCount() > { > Northwind db = CreateDB(); > > int numProducts = db.Products.Where("SupplierID=1").Count(); > Assert.IsTrue(numProducts > 0, "Expected results from dynamic > query"); > } > > [Test] > public void DL3_ProductCount() > { > Northwind db = CreateDB(); > > int numProducts = db.Products.Count(); > Assert.IsTrue(numProducts > 0, "Expected results from dynamic > query"); > } > > Andrus. > > > > ----- Original Message ----- > From: "Razwan Sarwar" <[email protected]> > To: "DbLinq" <[email protected]> > Sent: Tuesday, August 25, 2009 1:37 PM > Subject: [dblinq] LINQ Build a where clause > > > Hi > > > I am fairly new to LINQ and now face a problem that i can not solve > > alone, i need help. I have tried many things but not found a solution > > yet. > > > I have a webform with 2 dropdown lists and a text box. I am letting > > the user build a where statement based on what they choose. > > For example dropdownlist1: (dealername, dealernumber, location), > > dropdownlist2(<,>,<=,>=,==), and textbox is a free text field. > > > The where will be built as "DealerNumber <= 1001" > > > Now my code, will it be possible to change the where part to > > incorporate my controls? I am using "q = q.Where(c => c.DealerNumber > > == strDealerNumber);" > > can this be changed to: > > > field = dropdownlist1; condition = dropdownlist2; filter = textbox; > > q = q.where(field + " " + condition + " " + filter); > > > CODE: > > > using (PartsClassesDataContext db = new > > PartsClassesDataContext()) > > { > > List<spSelectFromMasterPartsResult> lst = > > db.spSelectFromMasterParts ().ToList(); > > > var q = from c in lst > > select c; > > > q = q.Where(c => c.DealerNumber == strDealerNumber); > > > return q.ToList(); > > } > > > Many thanks i appreciate all your help > > > Raz- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DbLinq" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/dblinq?hl=en -~----------~----~----~----~------~----~------~--~---
