-1

I am really confused. I followed this tutorial:

I know how to add but now i don't know how to add method , which get data from 2 table not from a table. Because the result i want have properties from 2 tables. A for example:

Customer:customerID,customerName

Order:OrderID,CustomerID,OrderDate

I want result:

CustomerID,CustomerName,Orderdate.

But i am confused because the class for customer and order are different. I don't know which type of result i should return so that i can binding into my gridview. If it's Customer type, OrderDate don't have. and same for Order. Someone please give me tip. Thank in advance.

Prabhu Murthy
  • 9,031
  • 5
  • 29
  • 36
TM500
  • 15
  • 6
  • i think you need to join this two table customerid to id – Jignesh.Raj May 04 '13 at 12:19
  • use join in your qeuery and use sqldataadapter to fill the dataset – Shafqat Masood May 04 '13 at 12:21
  • you can use joins and then get the entire set of orders for a customer Then may be you can bind that data to an `IEnumerable` where `CustomerData` will be an aggregate entity that has an `IEnumerable` for a customer so you can use them in the Grid or any UI. Jure Posted this as an answer while me keying in as comments, you can upvote and mark his answer – Saravanan May 04 '13 at 12:25
  • excuse me? I don't know how to get data via a query LinQ as var query = (from c in db.class from v in db.clscrs from n in db.course where c.ClassTitel=="yourinput" && c.classcode = v.classcode && v.coursecode = n.coursecode select n.CourseName).ToList(); – TM500 May 04 '13 at 12:33
  • excuse me? I don't know how to get data via a query LinQ as var query = (from c in db.customer from o in db.Order where c.id="001" && c.id = o.id select c.ID,c.name,O.orderdate).ToList(); and how to let my application run this query and after that i don't know store it into an IEnumerable( is T Customer or Order???). – TM500 May 04 '13 at 12:44

1 Answers1

0

You can create a new class that represents result you need from service method. Let's say:

public class MyCustomerResult
{
    public int       CustomerID{get;set;}
    public string    CustomerName{get;set;}
    public DateTime? OrderDate{get;set;}
}

And then create a method that returns your new class

public IQueryable<MyCustomerResult> GetMyCustomerByLastName(string startingLastNameLetter)
{
   //you should modify query to return data that you need, this is only example
   var q = from customer in this.ObjectContext.Customers 
           from order in this.ObjectContext.Orders
           where c.CustomerID = o.CustomerID
           select new MyCustomerResult
           {
              CustomerID=c.CustomerID,
              CustomerName=c.CustomerName,
              OrderDate=o.OrderDate
           }

     return q;
}
Jurica Smircic
  • 6,117
  • 2
  • 22
  • 27
  • excuse me! i want to get all data as that then how to write base on ID??? sorry i am newbie. – TM500 May 05 '13 at 03:09
  • select c.customerID,c.CustomerName,o.orderdate from customer c,order o where c. customerID=o.oderID could u please help me translate into linq??? – TM500 May 05 '13 at 03:18
  • @TM500 I updated the answer, i think thats the LINQ query you are looking for – Jurica Smircic May 05 '13 at 12:43