views:

82

answers:

2

In the business logic we map, Tables to Objects and fields of this table to properties. What to do in one-to many relationship? Just an example: I have Table, Products and Categories. I need to drag all products and instead of Category_ID (Products table) need to display actual Category name wich is stored in Category table.

What is propal way of doing it? In similar situations?

A: 

You can have a property on the Products Entity that is of type Category Entity. Check this link out from the EntitySpaces (an ORM for .Net) documentation for ideas: link text

Also, you may want to look into using an ORM.

thedugas
A: 

Hey,

Either use an ORM like LINQ to SQL or ADO.NET Entity Framework or strongly-typed datasets. But if you want to custom code your business layer, your Category class could have a Products collection property which contains those products, loaded from the DB, which you could infer the name.

HTH.

Brian
@Brian - the OP said he wanted to implement a one to many relationship, therefore the Product entity should not have a Categories collection but rather a Category entity as each Product can have one Category.
thedugas
Oops, I fixed the response. Thanks for the catch.
Brian
I want to try custom code, this is for my uni project. What if I have Tables - UserCar, CarMake, CarModel, UserCar - userId, carId, carMakeId, CarModelId CarMake - CarMakeId, MakeName CarModel - CarModelId, ModelNameSo I want to display on the page User car, using 3 layer architecture. So how do I map this tables??? to business object or objects??? Could you help me please?
Alex