Featured post
c# - Linq - Is there are way to build up a linq statement from several snippets of linq -
i have several methods use similar linq statements different enough them in own methods. say, sake of arguemnt, had following linq snippet repeated across methods (the real snippets longer this):
su.objid == serviceuserid cl.staffmemberid == staffmemberid
if working in sql contatenate repeated sql follows:
private string getrepeatedsql() { return "where su.objid = serviceuserid , cl.staffmemberid = staffmemberid"; } private void dosomething() { string mysql = "select * ...... lots of sql .." + getrepeatedsql() + ".. more sql"; }
(usual health warnings around contatenating sql string noted).
is there equivalent in linq? i'm sick of having make changes in several places - seems contravene dry principle.
thanks!
correct me if i'm wrong thought linq statements weren't executed until used them. (coming linq nhibernate)
if case add whatever need existing statement. example:
var temp=from x in sometable select x;
then adding clause:
temp = x in temp x.id==1234 select x;
then order by
temp=from x in temp order x.id select x;
i won't lie have never done way assume should work. if knows won't work please explain why. thanks.
found on msdn: http://msdn.microsoft.com/en-us/library/bb397906.aspx
in linq execution of query distinct query itself; in other words have not retrieved data creating query variable.
so creating variable have not retrieved data. although maybe way i'm doing above return data because calling from x in temp
change query.
- Get link
- X
- Other Apps
Comments
Post a Comment