WCF/WF - how to use query in wcf function - Asked By skumari woonna on 20-May-10 05:49 AM

I have 1 function in wcf.In this function i used linq to sql query.this function is working i got the result also.the finction is as below.here t1 is table name.here iam using only 1 table.

public IEnumerable<t1> GetSearchresults(string UID, string Aname, string Mname)


DataContext db = new DataContext();

int AID = GetAID(Aname);

int MID = GetMID(Mname);

IEnumerable<t1> data = (from p in db.t1

where p.MiD == MID && p.AiD == AID

select p).ToList();
return data;
i wrote 1 query usnig 3 table.I got the result also.the qurery is
select  MMetric.UId,UMA.AName,MMetric.Date,AModules.MName from    MMetric, UMA, AModules   where
MMetric.AID=UMA.AID and UMA.AID= MMetric.AID and AModules.MID=MMetric.MID
but i want the following code.
1)i want the query is converted to linq to sql query.
2)how to use this query in the function(in above function i used only 1 table and passing 3 parametrs).

Goniey N (Mr. G) replied to skumari woonna on 20-May-10 07:10 AM
Try This 

using (AdventureWorksEntities advWorksContext = new AdventureWorksEntities())
    string esqlQuery = @"SELECT contactID, AVG(order.TotalDue) 
                            FROM AdventureWorksEntities.SalesOrderHeader 
                            AS order GROUP BY order.Contact.ContactID as contactID";

/*  Your Query, In Your Query there is error
string squery = @"select  MMetric.UId,UMA.AName,MMetric.Date,AModules.MName from MMetric, UMA, AModules where
MMetric.AID=UMA.AID and UMA.AID= MMetric.AID and AModules.MID=MMetric.MID"

UMA.AID= MMetric.AID This Line You Write Two Time.  Si It May Be "UMA.UID=MMetric.UID"
        foreach (DbDataRecord rec in
            new ObjectQuery<DbDataRecord>(esqlQuery, advWorksContext))
            Console.WriteLine("ContactID = {0}  Average TotalDue = {1} ",
                rec[0], rec[1]);
    catch (EntityException ex)
    catch (InvalidOperationException ex)

//I Hope This Will Help You.....