How to use NHibernate with asp.net 3.5 - asp.net

I want to use NHibernate with Asp.net 3.5 but i don't know how to use it.I search on
Google but couldn't find the complete explanation about why to use NHibernate,Advantages of using it and integration with Asp.net projects.

I would suggest checking out Castle and NHibernate. I recently started using it and was blown away with what it can do. Castle manages all your sessions for you. Also it is easy to use LINQ with it.
Check out
http://davidhayden.com/blog/dave/archive/2008/04/28/NHibernateCastleActiveRecordTutorialUninitiated.aspx
Another great tool to use (Should work with ASP.Net) is the Nhibernate Profiler
http://nhprof.com/ It shows you what queries are being generated and the time its taking to run.
Also if you already have your database created you can download this tool http://www.agilityfororms.com/Home/Products/AfoCastleActiveRecordModelCodeGenerator/ It will create your models based on your database. Its works great for the most part. Although you have to register to download the free version still worth checking out.
Fluent NHibernate is supposed to be good as well although I have no experience with it. Might be worth checking out. http://fluentnhibernate.org/

You could have a look at this :
http://www.codegod.de/WebAppCodeGod/nhibernate-tutorial-1---and-aspnet-AID25.aspx
And this :
http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx

I'm nearing completion of my first project with it, and I've had mixed results. For basic data persistence, and assuming you already knew how to use it, it's much faster to build an application with it. You don't really have to worry about building stored procs and differentiating between new objects and updated objects.
On the other hand, until you're quite comfortable with it, it can take a long time to do something that would have been simple before. I've had a couple of problems, and it has been difficult and time consuming finding solutions to them.
To be fair, I've only written small applications with it and it has made the development process more difficult than I would consider required. The pain of using it is fairly similar from one app to the next, the benefits scale...

The best place to look is at NHibernate Forge. There's Blogs, wikis and groups that will help you out.
As for advantages of using it that is something you need to workout for yourself. Is it more advantageous than LinqToSql or Entity Framework? It depends on the project size and what you are actually looking for.

Related

Is there an EntityFramework "Light"?

we started a new ASP.NET MVC Project with EF and .Net 4.5. Original plan was to use code first to create the database, but that seemed a bit too complicated, probably mostly because all of us were familiar with DB-designs and it seemed just much easier and faster to do everything in SQL.
So for now we use EF to simply create mappers for our tables, views and functions. Stored Procedures don't really want to work for us automatically, so we are calling those manually with SqlCommand. Now a problem sometimes emerges with the complex connection string and all the XML-files which need to be referred in it. (At least which are referred when we use the automatically created connection string).
Long story short - EF has many features, of which we probably use only a hand full. We would be probably much happier with Linq2Sql. But that one is obsolete, and few months ago I read some scary posts, that when you want to launch your application in Azure, DB connections can break, and EF (from version 5 or 6) is so awesome and renews them automatically.
Is this true and EF the only usable ORM mapper for azure? Can we somehow deactivate all those features we don't use to have something as simple as Linq2Sql, should we use directly Linq2Sql even though it is obsolete, or just learn to deal with all those features? Or is the answer to use NHibernate (which seems to have a much more straight forward XML-configuration file, but no simple integration with Visual Studio to create all necessary classes)?
Update:
Another reason we gave up on code first and reverse engineered code first was, that we were missing an easy way to create wrapper functions for our SQL Server - stored functions. This feature is provided with the DB-first use of EF (as we use it)

Understanding a Big and Complicated ASP.NET Web Application

You might not like these kinds of questions, but I rely on the professionalism of StackOverFlow.
I have a very big ASP.NET web application, it contains many projects, a container (father) project, and multiple module projects. Obviously it's connected to a big SQL Server database as well.
This application doesn't have a specific documentation.
Is there a way (special tools, advices...) that would help me in understanding the functionality of the application gradually?
I meant by special tools, those that might be representing the structure of the system in diagrams or so.
I cannot find a way to start with.
Note: I'm using Visual Studio 2010, the application is built using .NET 3.5
Thank you for your opinions.
Personally, I usually prefer to start by looking at the database design. Depending on how it was set up, you should be able to create a database diagram which will show you all of the relationships between the tables.
Once you have a grasp of the database design, you should have a basic understanding of what the system is doing, which should give some context to the different processes and work flows throughout the web application.
If the application has a Sitemap, I would examine it throughly, as it should help you to better understand the flow of the application. If available, you should also look at the class diagram to see how the different classes relate to one another.
Without any kind of documentation, you'll probably have to use bits and pieces to understand how the application works. I'm not sure, but there may be some plugins available that can help you with this. Something like CodeRush or Resharper might be helpful. There's also a plugin called GhostDoc that might come in handy too.
Hope this helps.
Visual studio 2010 has architectural analysis it can perform on your projects with the ultimate version. This can help you in understand the app, what crosses layers, etc.
See:
http://msdn.microsoft.com/en-us/gg465276
http://www.slideshare.net/bgervin/visual-studio-2010-ultimate-architecture-experience-toronto-code-camp-2010-barry-gervin
You can have a look at this MSDN page, which will show you how to generate a UML diagram from your codebase. This will give you a rough overview of how things fit together, and what communicates with what (I haven't used this tool so I'm unsure of how much information is provided, or whether it is configurable).
Also, make sure you ask your teammates, or anybody else who has worked on this application before (there have to be a few such people around if it's such a huge project). They should definitely make the time to explain things to you, or at least answer specific questions you have.

Does anyone have an insight into ASP.NET WebFormsMVP?

Recently I ran into this open source project ASP.NET WebformsMVP.
It seems like an alternative to asp.net mvc and also a quick way to introduce testability into an existing webforms applications. (without having to go through the pain of rewriting a bunch of code to make it work for asp.net mvc)
Of couse community support and open-source projects abandonment is always a concern when trying new things, but moving on from those fears, has anyone giving it a serious try at this framework? If so, can you share some insight into its pros/cons and if it's really worth trying it?
Thanks a lot!
WebformsMVP is included in DotNetNuke now, so we have started using it indirectly as part of custom module development within DNN.
I don't think we're fully utilizing everything the framework is capable of, but have had no problems to date. The implementation is very clean and simple to implement, and retrofitting existing webforms code is fairly straightforward. For us the learning curve has been minimal.
We have run into a number of cases where we aren't certain of the "right" way to do things, and have found pretty limited guidance online. (Try as I might to avoid it, sometimes I just have to poke some stuff into the ViewState.) But, with it being used by the DNN team, we feel pretty confident that it will not fade away soon, and a growing number of examples should appear online.
Of course I encourage its use, even if only for the selfish reason of wanting to see the community grow.

.Net Custom Libraries?

Where can I get custom libraries for ASP .Net? Specifically I am looking for ready made database access library that allow me to select, insert and update a database using transactions. I know how to do create but I am trying to use an existent library that does all that and handles exceptions and errors so exempt from the hustle of creating that from scratch and go into errors.
You can use Microsoft's free Enterprise Library for DataAccess, Logging, Caching, Security and Configuration. It's very commonly used.
Also you can use code generators like free .NET Tiers, but you will need CodeSmith if you want to use it.
I'd suggest looking at either using LINQtoSQL and the DBML designer to map your database tables onto objects in your system or a more full-featured ORM, like nHibernate.
You may want to look at something called Speedy.net. I have never used it, but it looks interesting. I have used other code that these people have written, and normally it's pretty good. For the small amount of money that it costs it might be worth trying out.

Need advice on selecting a data access method

I am in the early stages of planning a conversion of a large classic ASP database application to ASP.Net and I'm having trouble picking out which data access method to use. I have played around with Linq To SQL, Dynamic Data, strongly typed datasets, Enterprise Library (Data Access Application Blocks), and a tiny bit with Entity Framework, but none of them have jumped out to me as "the one". There are just too many choices - my head is swimming, help me choose!
Perhaps it would help to give some background on the application that I am converting along with the priorities...
The back end is Microsoft SQL Server (2005 or later) and we are committed to that, so I don't need to worry about ever supporting a different database platform.
The database is very mature and contains a great deal of the business logic. It is highly normalized and makes extensive use of stored procedures, triggers, and views. I would rather not reinvent two wheels at the same time, so I'd like to make as few changes to the database as possible. So, I need to choose a data access method that is flexible enough to let me work around any quirks in the database.
The application has many data entry forms and extensive searching and reporting capabilities (reports are another beast which I will tackle later).
The application needs to be flexible enough to deal with minor changes to the database structure. The application (and database) may be installed at different sites where minor custom modifications are made to the database. Ideally the application could identify the database extensions and react appropriately. In other words, if I need to store an O/R mapping in the application, I need to be able to swap that out (or refresh it easily) when installing the application and database at a new site.
Rapid application development is critical. Since the database is already done and the user interface is going to closely match the existing application, I'm hoping to find something where we can crank this out fairly quickly. I am willing to sacrifice not using the absolute latest and greatest technology if it will save time in development. In other words, if there is a steep learning curve to using something like Entity Framework, I'm fine with going something like strongly typed Datasets and a custom DAL if it will speed up the process.
I am a total newbie to ASP.Net but am intimately familiar with Classic ASP, T-SQL and the old ADO (e.g. disconnected recordsets). If any of the data access methods is better suited for someone coming from my background, I might lean in that direction.
Thanks for any advice that you can offer!
Look at all three articles in this series:
High Performance Data Access Layer Architecture Part 1
Great advice.
You may want to look at decoupling the database layer from the asp layer so that you can not only give more flexbility in making the decision, but when you have to make changes to a customer's database you can just swap in a new dll without changing anything else.
By using dependency injection you can use xml to tell the framework which concrete class to use for an interface.
The advantage to doing this is that you can then go with one database approach, and if you later decide to change to another, then you can just change the dll and go on without making any changes to other layers.
Since you are more familiar with it why not just go directly to the database at the moment by making your own connections? Then you can move the rest of your code and along the way you can decide which of the myriad of technologies to use.
For a new application I am working on I am starting with LINQ to SQL for it, mainly because development will be quicker, but, later, if I decide that won't meet my needs I will just swap it out.
nHibernate might be a good fit. You can store the mapping in external configuration files which would solve your needs. Another option might be using ActiveRecord, which is based upon nHibernate.
nHibernate has a neat feature which you might find helpful. It's called a Dynamic property which is basically a name value pair collection populated by pulling the column names from the mapping file. So when you add a column at your client site, you update the mapping file and you'd be able to access the data through a collection on the object.

Resources