views:

335

answers:

2

Just a basic question. Learning Linq to SQL and some nHibernate. I am using the mvc tutorial and they drag and drop tables onto the visual studio designer to create the classes and wire up everything.

When I experimented with nHibernate I had to do lots with xml files. Does nHibernate have anything that is "easy" like Linq to SQL or is this drag and drop for Linq to SQL so basic that when I want to do something "real" it won't matter that Visual Studio does this for me (at this basic level)? In other words, the further I go with Linq to SQL, I'll eventually have to handle config files like I do with nHibernate.

+1  A: 

There is no "native" support like you see with LINQ to SQL. However, there are third party add-ins that will allow you to do something similar with nHibernate. My favorite is this one:

http://sourceforge.net/projects/nhibernateaddin

To use it:

  • Create a data connection to a database that contains the structure you are going to code against (your development database).

  • Add a new NHibernate plug-in item (via add new item) to your project that will contain you domain objects. In the property window add the data connection string from the data connection you just created (this isn't automated yet).

  • Finally, you drag and drop your tables from your data connection to the NHibernate plug-in object and when saved your mapping files and you domain objects are generated. To use it you create a data connection to a database that contains the structure you are going to code against (your development database).

James
Interesting - hadn't heard about that plugin before. BTW, did you mean to include the same paragraphs twice? :)
Gabriel Florit
Nope. Fixed. Thanks. :)
James
+3  A: 

Look at Castle's ActiveRecord framework. It replaces the use of XML config files with the use of Attributes directly on the class/property declaration. Also, a tool called ActiveWriter integrates with Visual Studio and allows connecting to a data source and generating the object model!

Anthony Mastrean