Mapping SQL 2008 datetimeoffset using nhibernate - nhibernate

Is there any supported way of mapping datetimeoffset the new datatype in SQL 2008 to the System.DateTimeOffset using nhibernate?

NH 2.1 (or compiling from NHibernate trunk) supports this and more out-of-the-box. Check it out

(Assuming google didn't turn of anything)
You will probably need to create a simple IUserType to handle this, also I am sure that the NH team would gladly accept it as a patch for everyone to benifit.
Ayende has a good post here on this. He goes though a couple of options to solve his problem so you might want to start from the bottom of the post (not the comments) and go up.

Related

Audit trail techniques

My project is in ASP.NET MVC3, SQL Server 2008 and using Fluent NHibernate.
I now have a requirement to audit certain properties of a specific object.
i.e. recording the old and new value of the properties changed on that object and also create and delete events on the object itself.
I think there can be several ways to approach this task - database triggers, INotifyPropertyChanged interface, or any NHibernate provided features?
Alternatively any open source libraries that will make my life simpler.
However, what i am not sure about is which path to choose. I mean this is a very vast area where I can go on exploring and still can't come to any conclusion.
It will be really helpful if I can get some guidance as to which option will be best considering my requirement and I can look into it more from there.
Thanks a lot.
Maybe I'm a bit biased but...
Have you had a look at Envers? https://bitbucket.org/RogerKratz/nhibernate.envers

Batching in NHibernate for Informix database

Im using Fluent NHibernate for Informix database. I need to use batching concept for bulk insert and update. Can anyone give me suggestion for that. I found out that by default batching in Nhibernate supports only SQL and Oracle. By anyway we override it and also support informix?
I know this does not directly answer your question but somebody has provided a patch for batching in MySql. You may be able to take this patch and apply the logic for Informix.
Link to patch is on NHibernate Jira

Getting Started with Fluent NHibernate

I'm trying to get into using Fluent NHibernate, and I have a couple questions. I'm finding the documentation to be lacking.
I understand that Fluent NHibernate / NHibernate allows you to auto-generate a database schema. Do people usually only do this for Test/Dev databases? Or is that OK to do for a production database? If it's ok for production, how do you make sure that you're not blowing away production data every time you run your app?
Once the database schema is already created, and you have production data, when new tables/columns/etc. need to be added to the Test and/or Production database, do people allow NHibernate to do this, or should this be done manually?
Is there any REALLY GOOD documentation on Fluent NHibernate? (Please don't point me to the wiki because in following along with the "Your first project" code building it myself, I was getting run-time errors because they forget to tell you to add a reference. Not cool.)
Thanks,
Andy
I've been using Fluent NHibernate Automapping for a few months now. I'm by no means an expert, but can take a stab at your questions...
FNH Automapping does indeed create DB schemas from POCO classes, including lists of other objects (this was the reason I chose NHibernate in the first place).
When you change schemas, you have to rerun the automapping, which does drop the whole database, unfortunately. In my case, it's not a big problem because I'm importing existing binary data files, so I just have to re-import my data every time the schema changes. I've read that there's some data migration support available with NHibernate, but have no experience with this. (BTW, Subsonic will do data migration, but it's automapping functionality is far more rudimentary - at least it was when I evaluated it a few months ago)
FNH documentation is one of my pet peeves - they have not even added Intellisense help on the method names, etc. (But they get really huffy when you point that out - ask me how I know!) I've made a couple of edits to the wiki when I could, but there's so much more that could be done there. The best approach is to start with a working example (i.e.
this one from Nikola Malovic, and post questions to the support form if (when!) you run into trouble. In general, I've found the FNH community pretty helpful, and have been able to work through all my difficulties. They've also fixed a couple of bugs I've found.
Overall, using FNH has been a huge win for my project - highly recommended!
I don't use Fluent, but I can help with classic NHibernate.
yes, the creation of the schema is very recommendable for production use (Schema Export). When you do this is up to you. For instance, you could create the database by an installer. You shouldn't drop existing databases, but this is a decision of you application.
I don't understand this question. Do you mean you need to upgrade an existing database to a new database schema? This is unfortunately something you need to implement yourself. NH can't do much about this, because it is very specific to you data and the changes you made. There is also a Schema Update or something like this, which is not recommended for production use.
I don't use Fluent, so I can't help here.

How to Map oracle datatype SYS.XMLTYPE in Nhiberbate

I have a table in oracle having column of datatType SYS.XMLTYPE and have to map it in Nhibernate hbm to retrieve the XML. I am using C# with .net framework 3.5 is there any specific dataType available to map this or can i use byte[] or char[] for mapping?
Thanks
Arvind
I think the best approach would involve creating an NHibernate UserType, although you might be able to get read only access using a formula approach and mapping as a clob type.
There is an example of doing this in Hibernate that might be easy to port across to .net (see also this forum post and this blog post)
Generally I find it useful to search for solutions to these kind of problems using a keyword of "Hibernate" as well as "NHibernate" for these issues as the solutions are often easily portable to NHibernate
use XMLDOC...it works like charm

Nhibernate and History Tables

I am working on a ASP.NET MVC website using Nhibernate as my ORM. The project is similar to a wiki/blog engine and requires that as pages are edited they store a history of the edits in another table which can then be viewed and recovered. This is complicated somewhat in that each "page" can have collections associated with it that can also be edited/added/removed. I would also need to stored these changes.
I was wondering how this fits into an entity mapping scenario such as Nhibernate and how this might be implemented. If anyone knows of any articles on this, or has done this themselves then please let me know.
I was considering triggers but I would prefer not to mix data access technologies if possible. I also am using MySql so CDC would not be possible for me.
Thanks
Either implement an auditing interceptor or use the event system. The event system is newer, I haven't found any auditing examples yet...
Also see this related question:
Take a look at NHibernate.Envers https://bitbucket.org/RogerKratz/nhibernate.envers