Click here to Skip to main content
14,691,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I´m doing a small project for work, and I´m struggling a bit on how to create BLL objects in relation to the Database.
I have 2 questions (so far ...):
- How to represent foreign keys?
I would like to be able to use the instances for some logic (Ex: Shipment.Dispatcher.Name )), but in order to bound it to a control or update it I need the id.

- How to deal with master details?
With the example _items, should I make it public?, create a get only property? other way?

As an example I have 3 tables: Clients, Shipments and Items
I thought in doing it as you see below but I´m not feelling confident ...

What I have tried:

public class Shipment : INotifyPropertyChanged
{
	private int _id;
	private int _dispatcher_id;
	private Client _dispatcher;
	private List<Item> _items;
	
	public int DispatcherID
    {
		get
        {
			return _dispatcher_id;
        }
        set
        {
            _dispatcher = new Custom(value);
            _dispatcher_id = _dispatcher.ID;
            NotifyPropertyChanged();
        }
    }

	public Client Dispatcher    
	{
		get
        {
			return _dispatcher;
        }
    }		
}

How would you do it?
Thank you for your time.
Posted
Updated 20-Jul-17 8:39am
v2
Comments
Tomas Takac 18-Jul-17 7:21am
   
If you already have your database you can generate your object model from it using Entity Framework [^].
Er. Puneet Goel 18-Jul-17 7:47am
   
Are you using MVC or asp.net webforms ? Also post if you wants to use Entity framework.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900