Using classes in ORM based projects

This question is about "best use" scenarios in ORM projects like NHibernate, Subsonic, Linq2SQL, etc.

All of these tools generate base entity classes, some with attributes and others without. Are these classes used as their business classes? Or is there an optional copy of data from ORM generated classes to handcrafted business classes?

Thank.

0


source to share


4 answers


I tend to work the other way around. I create business objects the way I need them and create NHibernate mappings from my objects to data. You can force NHibernate to create a schema for you based on your mappings, or you can create your own schema and create mappings between them. Linq2Sql and Entity Framework don't support this. I cannot speak to Subsonic on this matter.



I usually create my business classes and get the application at least partially, without any database. This way I can better understand what this application is supposed to do and how it should behave before deciding how to store the objects.

+5


source


There are several solutions for all the tools mentioned, the answer depends on the scope of your project.

Here's a similar question about LINQ to SQL that I answered a bit back.



Hope it helps!

+1


source


I usually use entities directly in the business and presentation layers. The data layer defines the object, the business layer processes the object or requests a list of entities, and the presentation layer displays the entities.

I think that creating separate business objects and copying data between them would be a lot of unnecessary overhead. But if you find that you need to do this, I would recommend just wrapping the objects instead of copying the data back and forth. You can hide an object and use Properties to expose participants and change behavior.

+1


source


SubSonic and Linq2Sql is a custom orm matcher. Consider a situation where the database is normalized. For example, employee information is split into three different tables, but in your domain model, you only need one Employee object to represent the information. This is where SubSonic and Linq2Sql fail. NHibernate allows you to map a domain object to multiple tables. Also you want to stay away from the auto-generated code. NHibernate allows you to define your own POCO (Plain old C # object) domain and has different ways that allow you to map this to tables in the database

+1


source







All Articles