0

I'm new to this all and I like to know how experienced programmers handle the following situation

Let's say I have a table "Supplier" with some common fields and also fields MailingAddress, BillingAddress which are 2 key fields to link to another table "Address"

TB Supplier

Id = 1 Name = MyNameFoo MailingAddressId = 100 BillingAddress = 101

TB Address

Id = 100 Street = MailingStreetFoo City = MailingCityFoo

Id = 101 Street = BillingStreetFoo City = BillingCityFoo


I have a 4 layer application solution:

project xyz.WPF which hold al my WPF windows to presentate the data to the user (Listbox with Binding)

project xyz.Business : in between WPF and DataAccess (SupplierB.vb, AddressB.vb)

project xyz.DataAccess.SqlServer : data layer (SupplierDAL.vb, AddressDAL.vb)

project xyz.Entities : to store my entity classes, each representing a table and just holding properties. I use this to pass from one layer to another (SupplierE.vb, AddressE.vb).

SupplierDAL class gets data from SQL Server and returns a "List(Of SupplierE)" to SupplierB class which return this "List(Of SupplierE)" to the WPF where it is bound to listbox -> Listbox.ItemsSource = SupplierB.GetAllSuppliers().


Now I can get all suppliers and show them in a WPF window in a listbox (or datagrid, ...) Also I can get all addresses and show them.

But at some point I want to get all the addresses (Mailing, Billing) for one Supplier. I know how to write my query with linq (join the 2 tables) but what do I have to do with the result of it. It is not a SupplierE nor a AddressE; it's a combination of the two. I want the result to be an object that I can pass around the layers, just like SupplierE.vb, AddressE.vb. Of course I could make another entity like SupplierAddressesE.vb; problem solved but in my real live solution I have dozens of join queries with joins between several different tables (not just Supplier, Address).

So a lot of tables, a lot of join query results; does this means I have to make a entity object (xxxE.vb) for each different join query or is there another way we can do this in a 4-tier layer application with Linq to Entities?

Thanks for any reply which can direct me to a good approach for this situation Luc

Spoelle
  • 163
  • 1
  • 1
  • 8

1 Answers1

0

If you are lazy loading the entities, then your supplier entity should have the attached address entity for each of Mailing/billing. Why not just have create a proper Supplier class that has properties for Mailing/Billing that are Address classes as opposed to Ids?

Wil
  • 2,328
  • 2
  • 20
  • 27