Tables which contain a foreign key normally represent a greater entity's details.
Both EmpDetails
and EmpDocuments
represent a different detail level of your greater entity Emp
.
Since you may have many documents and many details for each Emp
instance, your details tables shall be gathered as a list inside of your emp
class.
public class emp {
public int Id { get; set; }
public string Name { get; set; }
public int DepartmentId { get; set; }
public IList<empDetail> Details {
get {
return _details;
}
}
private IList<empDetail> _details;
public IList<empDocument> Documents {
get {
return _documents;
}
}
private IList<empDocument> _documents;
}
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 SchemaExportTool
from 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:
- NHibernate Reference Documentation
- Basic O/R mapping
- ISessionFactory Configuration
- Speaking of architecture : NHibernate Architecture
- Collection Mapping --> Pretty useful for mapping your two
empDetail
and empDocument
collections within your emp
entity class.
- A Nice Tutorial
A few advantages of using NHibernate:
- Never get bothered designing a relational model again;
- Don't bother about the underlying datastore, NHibernate supports multiple database engines by simple XML configuration file (no need to recompile the application for any of the underlying databases);
- Increase your development by easily from 25% to 50% or over once you master 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:
- Data Access Application Block;
- Exception Handling Application Block;
- Logging Application Block;
- Security Application Block;
- Unity Application Block;
And I may forget some others...