Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ADO.NET WPF C#4.0 MVVM
I have a classic Ado.net entity like Clients and Orders. Also I have a WPF window and using Mvvm architecture. I am new to mvvm and Ado.net so I cant figure out how can get my datagrid(that using one itemsource) show items from clients table and orders table. Its might sound obvious but problem is taht my Orders property(that i set as ItemSource for datagrid) dont have items from clients table.
 
My methods to get data from db:
Orders:
public IEnumerable<Order> GetOrders()
        {
            using (var context = new SvLaserEntities())
            {
                var result = context.Orders.ToList();
                result.ForEach(e => context.Detach(e));
                return result;
            }
        }
Clients:
public IEnumerable<Client> GetClients()
        {
            using (var context = new SvLaserEntities())
            {
                var result = context.Clients.ToList();
                result.ForEach(e => context.Detach(e));
                return result;
            }
        }
Posted 20-Apr-13 10:44am
Edited 20-Apr-13 11:15am
v2
Comments
ThePhantomUpvoter at 20-Apr-13 15:50pm
   
How could we correct your code when we cannot possibly see it?
Alex Define at 20-Apr-13 16:16pm
   
Well, I thought about an algorithm or advice, but added some code;
ThePhantomUpvoter at 20-Apr-13 17:15pm
   
Well since you did not provide any relevant information for whatever your problem is, the only advice is could offer is; get the orders from the orders table and then assign the result to your Orders property.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Are the two tables connected in your database at all? If not, you likely have to redesign your database slightly. Typically, an Orders table would have a ClientId of some sort, which is a primary key of the Clients table and a foreign key in the Orders table. If you did that, then you could pull the Clients data from the Client table and the relevant Orders using something like:
 
foreach(Client c in context.Clients)
{
    // do something with c...
    Order o=c.Orders;
    // do something with o...
}
 
Best of luck!
  Permalink  
Comments
Alex Define at 21-Apr-13 3:01am
   
Thank you! Works great :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 562
1 Sergey Alexandrovich Kryukov 484
2 Maciej Los 325
3 DamithSL 233
4 Mathew Soji 195
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 20 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100