Noob question about 1:M and setup

Posts   
 
    
VBAHole22
User
Posts: 18
Joined: 12-Nov-2008
# Posted on: 22-Sep-2009 17:03:51   

I'm trying to get a grasp on how i can best use llblGen in my C# code and i'd just like a little kick start to get my brain going in the correct direction. My setup is that i have this normalized db structure for storing people and their contact info. So i have a table with people, a table with addresses, a table with phone#s, table for emails, etc.. For each of those i have bridge tables that way if 20 people reside at the same address i only have that address once with 20 records in the bridge table.

Sometimes people have address but not phone numbers or emails. So I created this massive view with a bunch of left outer joins so that i could have all of my people in the view regardless of whether they have all of the info that makes a 'complete' person.

I was then going to map an entity off of this view. Does this sound like a good idea? I know that llblGen has ways of handling these kinds of relationships so maybe i should be making entities on each of the tables and use those instead?

I'm confused is what it boils down to. But i do know what it is that i need. I need a REST service tier on top of this db so that i can get back people info based on search criteria. I know that sometimes a person can have many addresses so i want to be able to get the person and the address set, or phone set, etc.

I know this is a very vague question. I'm open to any suggestions at all - even RTFM if you have ideas about where to start. Thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 22-Sep-2009 21:03:52   

Although we do refrain from "RTFM" as a response as much as we can, it does repay reading. simple_smile There is a LOT of useful information and examples in there.

Your idea of creating one entity based of one big view is generally NOT the right way to go. Entities are meant to represent a single "unit" of information - generally one record from one table.

As long as you have the PK-FK relationships set up correctly in your DB the LLBLGen designer will find these and create the correct structure of entites to represent you data model.

So from a Person object you would be able to access the PersonEmail property which would be a collection of PersonEntity objects. Each object in the PersonEmail collection would have an Email property, which would give you an Email entity.

In your example where a person had no phone numbers - the PersonPhoneNumber property would be an empty collection.

LLBLGen makes it very easy to retrieve a Person and all their related info - how this happens depends on if you are using the SelfServicing or Adapter. In SS the related entites will be lazy loaded on demand as you access them. In adapter you need to specify that they should be fetched at the same time as the entity using PreFetch paths.

Hope this gives you an insight on how to get started - feel free to come back with any other questions.

Matt