nhibernate

nHibernate List mapping without key column?

I have the following entities. class Parent { public virtual int ID {get; set;} public virtual string Key {get; set;} public virtual string Type {get; set;} public virtual string Value {get; set;} public virtual IList<Child> Children {get; set;} } class Child { public virtual int ID {get; set;} public virtual string Paren...

ASP.NET with NHibernate - How can I get the ID of an entity just inserted on postback

As per title. Using native ID's The only thing I can think to do is to call GetByExample(entityJustInserted) and pick the one with the highest ID. Not great...anyone got a better way? Thanks. ...

Getting mapped entities from an ISQLQuery without AddEntity

Hello all, consider these POCOs: class Foo { int Id {get;set;} string Name {get;set;} } class Bar { int Id {get;set;} string PropA {get;set;} Foo PropB {get;set;} } Now what i want to achieve is using an ISQLQuery with a root entity of Bar to also hydrate the PropB property. ISQLQuery barsAround = nhSes.CreateSQLQuery("s...

Failing NHibernate test causes ReSharper test runner to hang for 30+ seconds

I have some NUnit integration tests to test my FluentNHibernate mappings using a SQLite in-memory database. I am using the ReSharper test runner (v5.0.1659.36) in Visual Studio 2008. When one of the NHibernate tests fails, the ReSharper test runner and Visual Studio freezes for 30+ seconds. (It will show that it failed but not show the...

Nhibernate <version> feature not working

Hi I have just started working with NHibernate. Have found it pretty good till now but have hit an issue that I am unable to solve. Any help will be greatly appreciated. I am trying to use the "version" feature to help implement optmistic locking. Below is my mapping file and a portion of code from the related class. My problem is that...

NHibernate/LINQ - Aggregate query on subcollection

Querying child collections has been a recurring issue in our applications where we use NHibernate (via LINQ). I want to figure out how to do it right. I just tried forever to get this query to work efficiently using LINQ, and gave up. Can someone help me understand the best way to do something like this? Model: ServiceProvider ...

NHibernate save object, a column is null

hi,the database has two table,one is mb_user table and other is mb_comment table。A user have some comments.When I insert a comment into mb_comment ,the comment_user_id of mb_comment is null.I can't save value of comment_user_id.Please help me! Map file mb_user Map file <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="u...

How to export hbm xml files using s#arparchitecture with fluent mappings

This question was asked before but the answers all show how to export the hbm files from fluentnhibernate. We are using S#arpArchitecture which wraps fluent. I am able to export the schema but what I really want is the xml files to troubleshoot errors. I've done this using FNH before but adding S#arp to the mix has complicated things wh...

Starts with doesn't work in Linq to NHibernate query

In my repository I have: public IQueryable<ICustomer> GetByAddress(string address) { return from c in GetSession().Linq<ICustomer>() where c.Address.StartsWith(address) select c; } The SQL I'd like it to generate is essentially: SELECT * FROM Customer WHERE address LIKE @address + '%' However, whenever I d...

Nhibernate mapping join on foreign key

Is there any way to get Nhibernate mapping to perform a join between a child and parent tables I have a product table and a product group table. there is a key between these tables of GroupId. When i use a join in mapping for a Product it tries to Join on the ProductId to the GroupId instead of the GroupId to GroupId. Is there no easy ...

Update of many-to-many collection in Nhibernate causing multiple deletes in join table

I have a class that conatins a collection that is mapped to a many-to-many database relationship using Fluent Nhibernate. The mapping is as below - Table("Book"); Id(x => x.Id); Map(x => x.Title); Map(x => x.NumberOfPages); HasManyToMany(x => x.Authors) .Cascade.AllDeleteOrphan() .Table("BookAuthor") .ParentKeyColumn("BookId") .ChildKey...

NHibernate ICriteria - order by child collection count ?

Hi, Here is a simple example scenario - A 'Tag' has many 'Questions'. When I get a list of Tags how do I order by the Tags Question Count using the Criteria API? I have done this before but haven't touched NH in about 4 months and have forgotten... projections maybe? help!!! Thanks ...

Quoting column names with NHibernate and PostgreSQL

I have started to use NHibernate 3.0 and PostgreSQL for a small project, so far the ride has been a little rough due to the NHibernate site being down and I'm sure this answer is on their website somewhere. I have a database that has these two columns(of course there is more in the real table): int ID String Feature now I'm using a F...

How to convince an organization to use NHibernate?

I know it's not a "programming" question per-se, but come on guys - give me a break here... I'm working at a large scaled, really slow organization. We recently started a process to decide on a new ORM technology. After looking in various forums, and test-programming with NHibernate, I think it's awesome. Only problem is, I know that...

Nhibernate formula appending template word to sql keyword

I am using the following formula in my mapping file : select top 1 SI.ID from Table SI with(nolock) where SI.GUID = GUID And SI.IsArchive = '0' the genrated sql is : select top 1 SI.ID from Table SI with(this_.nolock) where SI.GUID = this_.GUID And SI.IsArchive = '0' The nolock is a keyword. I don't want it to be qualified with this_...

Nhibernate Generat wrong SQL for Oracle with locking

yesterday I've been trying to make this code work inspite the fact it's just working fine with nhibrnate and SQL server but when it come to oracle it generate wrong sql UnitOfWork.Current.CreateCriteria<Bill>().Add(Restrictions.IsEmpty("ReqId")) .SetMaxResults(BatchSize).SetLockMode(LockMode.Upgrade).List<Bill>(); the generated SQL w...

nhibernate, async loading

I have a question about hibernate. I use different controls in my application (treeview, combobox, ...). I get the content for these controls through nhibernate. The problem is, that it takes a lot of time to get the data. Drung this time the form is frozen. I want to load the data in another thread. But i don't know where to put that t...

Fluent NHibernate 1.1 with Microsoft Access 2007 Database

Is it possible to use Fluent 1.1 with Access? I found this site here that shows how to create a configuration file that can be passed into Fluently.Configure(config). The issue with this is that you need to use NHibernate 1.2.1 which Fluent gets upset with because it has a reference to version 2.1.2.4000. Here is the error: Error 1...

SQL Server - table seems to be blocked

Using NHibernate, I have just attempted to save a graph of objects using NHibernate. The save failed due to a not-null constraint violation. I am now finding that a table in the database corresponding to one of the objects in the graph now appears to be locked. I cannot query it. Whenever I try, it just sits there doing nothing until I ...

Recommendations for generating printable reports/invoices?

I have an ASP.NET website from which the users themselves will generate custom reports and (possibly) print them. My question is what approach would you recommend (and why): Generate the report using reporting software like Microsoft Report Viewer or Crystal Reports. Use simple ASP.NET pages and format the page for printing using CSS. ...