nhibernate

Strategies for Mapping Views in NHibernate

一曲冷凌霜 提交于 2019-12-30 08:26:16
问题 It seems that NHibernate needs to have an id tag specified as part of the mapping. This presents a problem for views as most of the time (in my experience) a view will not have an Id. I have mapped views before in nhibernate, but they way I did it seemed to be be messy to me. Here is a contrived example of how I am doing it currently. Mapping <class name="ProductView" table="viewProduct" mutable="false" > <id name="Id" type="Guid" > <generator class="guid.comb" /> </id> <property name="Name"

Using NHibernate ICompositeUserType with a value type

拟墨画扇 提交于 2019-12-30 08:15:23
问题 I have a domain model object which has properties of type System.DateTimeOffset. I'm using a database which doesn't support this type natively, so I'm planning to store it using a column of type 'datetime' and one of type 'smallint'. I've dug around on how to map this using NHibernate components, and found that it could work using an ICompositeUserType instance. However, upon implementing the interface, I've come across the method called "SetPropertyValue" which ostensibly sets a property

Nhibernate + QueryOver: filter with Where ignoring sensitive

给你一囗甜甜゛ 提交于 2019-12-30 08:09:37
问题 I am trying to build a simple query in nHibernate with QueryOver but I want it to convert everything lower-case or ignore sensitive: Domain.User User = Session.QueryOver<Domain.User>() .Where(x=>x.Login=="username") .SingleOrDefault(); How can I achieve this? UPDATE : Someone suggested that the problem could be with the colletion of the DB but I've never had any kind of problem with that and this script works: Domain.User User = Session .CreateCriteria<Domain.User>() .Add(Expression.Eq("Login

Does Nhibernate session.BeginTransaction auto rollback on exception within Using

匆匆过客 提交于 2019-12-30 07:56:23
问题 Ok sorry for the long subject name... If I do the following: using (var transaction = session.BeginTransaction()) { // do something transaction.Commit(); } If my do something caused an exception, would it auto rollback, or do I need to explicitly check for this like below: using (var transaction = session.BeginTransaction()) { try { // do something transaction.Commit(); } catch (Exception) { transaction.Rollback(); } } 回答1: It's a safe assumption that the transaction will be rolled back if

Order By Rand by Time (HQL)

谁说我不能喝 提交于 2019-12-30 07:54:46
问题 I'm developing a web application using asp.net Mvc 2 and NHibernate, and I'm paging data (products in a category) in my page, but this data are random, so, I'm using a HQL statement link this: string hql = "from Product p where p.Category.Id=:IdCategory order by rand()"; It's working fine, but when I page, sometimes the same product appears in the first, second, etc... pages because it's order by rand(). Is there any way to make a random order by fixed by period (time internal) ? Or any

NHibernate mappings issue when referencing class (lazy load issue?)

柔情痞子 提交于 2019-12-30 06:57:39
问题 I'm using NHibernate + Fluent to handle my database, and I've got a problem querying for data which references other data. My simple question is: Do I need to define some "BelongsTo" etc in the mappings, or is it sufficient to define references on one side (see mapping sample below)? If so - how? If not please keep reading.. Have a look at this simplified example - starting with two model classes: public class Foo { private IList<Bar> _bars = new List<Bar>(); public int Id { get; set; }

NHibernate mappings issue when referencing class (lazy load issue?)

此生再无相见时 提交于 2019-12-30 06:57:07
问题 I'm using NHibernate + Fluent to handle my database, and I've got a problem querying for data which references other data. My simple question is: Do I need to define some "BelongsTo" etc in the mappings, or is it sufficient to define references on one side (see mapping sample below)? If so - how? If not please keep reading.. Have a look at this simplified example - starting with two model classes: public class Foo { private IList<Bar> _bars = new List<Bar>(); public int Id { get; set; }

SQLite: sqlite3.dll vs System.Data.SQLite.dll?

跟風遠走 提交于 2019-12-30 06:53:07
问题 What do I need to use SQLite with NHibernate (and FluentNHibernate ) ? There is: System.Data.SQLite.dll and System.Data.SQLite.Linq.dll , (ADO.NET 2.0 provider) available from http://sourceforge.net/projects/sqlite-dotnet2/ and sqlite3.dll available as binary download http://www.sqlite.org/download.html What is the difference? Do I need both, or which one? The first option installs to C:/...Program Files. Can I copy it from there to my custom SharedLibs folder, or will something reference the

Inner or Right Outer Join in Nhibernate and Fluent Nhibernate on Many to Many collection

馋奶兔 提交于 2019-12-30 06:39:28
问题 How can I force NHibernate to do a RIGHT outer join or an INNER join instead of a LEFT outer join on a many to many collection? The reason I would want to do this is because of filtering applied to the collection elements. With a left join, you get the same number of rows returned as an unfiltered query, but the elements that are filtered out just show NULL for all of the fields. However, with a right join, the correct number of rows and elements are returned from the query. I would expect

NHibernate - Execute SQL to populate DTO

六月ゝ 毕业季﹏ 提交于 2019-12-30 06:34:28
问题 I have some instances for reporting where executing sprocs is easier and simpler than complicated QueryOver statements. I have a DTO, not an entity, that represents the data returned from the query and want to populate the results of the query into the DTO. I am using named queries and session.GetNamedQuery() to execute the query. Do I have to create mapping files for the DTO? If so, is is possible to let NHibernate/FluentNHibernate know that it should not create tables for the DTO? My units