How to retrieve data from database using nhibernate - nhibernate

I am using VS 2010, SQL 2008 with nhibernate to perform database operations.
I know that we can use hbm.xml file to join 2 or more tables. I want to know how to make use of this file in retrieving the data by using the joins specified in this file?
Pls help me. Or any link which gives me info on this.
Thanks,
Pavan

It sounds like you need to read over the nhibernate documentation. The first few sections give a rough overview of how hbm files map to POCOs (objects) and your database.
You should also read the Getting Started Guide on nhibernate.info. These will answer your somewhat vague question above.

Related

How to convert SQL query to key-value command

Is it possible to use some opensource project to help parse the sql query and convert it into the custom key-value db command (CRUD on the key). I saw the architecture of the tidb, and it seems like they have an abstracted layer. I would appreciated anyone pointing to some resources to help start the process.
I did try to research other project out there, and it seems like most of them have ad-hoc and embeded the parsing layers into their db, so I cannot really decouple and use their solutions.
You can refer to this blog:https://www.pingcap.com/blog/tidb-internal-computing/
But I don't think it is easy to decouple the code from TiDB.
You could use an SQL parser like https://github.com/pingcap/tidb/tree/master/parser but then you would have to add something that does the actual storage operations.
If you want transactions you might want to check this:
https://tikv.org/deep-dive/distributed-transaction/percolator/

XSD to SQL Server conversion

I have a question in regards to the SQLXML for SQL Server.
My assignment is to convert an XSD file so that it magically "becomes" tables in the SQL Server database. I've looked around everywhere, on all the links I could possibly find, but nothing clicks. Everything is like a half-step of what I need to achieve.
I am not too familiar with Visual Studio, haven't done much else than running database queries and all the stuff one likes to do in a SQL Server database. Except for XML.
I figured that SQLXML from Microsoft's MSDN would be a good tool to have (and I believe it's already installed).
Any tips or solutions?
Thanks.
There's no magic involved, and as it's homework/study I won't detail how to do it myself, but if you direct your research towards SQL's Bulk Load functionality it would seem to be what you need.
Read this article for a brief "how to" guide.
Or this article for a detailed description of how to use it.
You can convert XSD to SQL using this approach https://github.com/ujhgj/xsd2sql
But I'm not sure of SQL dialect. That thing worked for Mysql.

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.

Mapping files generation with nhibernate

i m new to nhibenate and i really find it painful to write the entire mapping files is there a tool or a vs addin that helps you do the mapping ?
thx for your time :)
If you have an existing database that you want to map you can use the open source tool MyGeneration to create both mapping files and the domain objects from the database. In this screencast you can see how this can be done.
You can also use CodeSmith, however this is a commercial tool. This screencast shows the use of this tool with NHibernate.
If you write the XML yourself, make sure that you have intellisense in VS. This blog describes how this is done.
If it is just the XML you don't like, check out http://wiki.fluentnhibernate.org where you do the mapping with C# code. Check out this blog post (mine) for an example.
You can also do the mapping with Attributes, but there seems to be not to many examples of this.
You can also check out Caste ActiveRecord, which "is built on top of NHibernate, but its attribute-based mapping free the developer of writing XML for database-to-object mapping, which is needed when using NHibernate directly". Here are some tutorials on this.

NHibernate mapping xml data to database

I have xml files containing data that I wish to insert into my database using Nhibernate. I can write some Linq that will process my data and map it to my nhibernate objects but I was wondering if there was some way of doing this without the need to write the translator from XML to Nhibernate myself.
Am not sure if something exists along these lines or if anyone has written something in the past to get XML data into the database using NHibernate.
Thanks for any suggestions!
I believe this is what your looking for:
http://markmail.org/message/3jkwktw6226357qs