I have three tables as shown below
Emp
----
empID int
empName
deptID
empDetails
-----------
empDetailsID int
empID int
empDocuments
--------------
docID
empID
docName
docType
I am creating a entity class so that I can use n-tier architecture to do database transactions etc in C#. I started creating class for the same as shown below
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace employee
{
class emp
{
private int empID;
private string empName;
private int deptID;
public int EmpID { get; set; }
public string EmpName { get; set; }
public int deptID { get; set; }
}
}
My question is as empDetails and empDocuments are related to emp by empID. How do I have those in my emp class.
I would appreciate if you can direct me to an example.
Thanks
Tables which contain a foreign key normally represent a greater entity’s details.
Both
EmpDetailsandEmpDocumentsrepresent a different detail level of your greater entityEmp.Since you may have many documents and many details for each
Empinstance, your details tables shall be gathered as a list inside of yourempclass.Using NHibernate, you could simply don’t care about your database relational model and have this tool generate your database relational schema automatically using the
SchemaExportToolfrom your class diagram through XML mapping files (Follow this link for an overview).There are multiple plugins, if we may call them so, to NHibernate such as
Fluent NHibernate (FNH),Linq to NHibernate.Here are some useful links which shall help you get acquainted with it:
empDetailandempDocumentcollections within yourempentity class.A few advantages of using NHibernate:
Otherwise, there is also Microsoft Enterprise Library which I often use in conjunction with NHibernate, or depending on the projects, I may prefer only use EntLib with the different application blocks:
And I may forget some others…