nhibernate

NHibernate - how to switch dynamically the generator for Id?

和自甴很熟 提交于 2019-12-25 10:06:27
问题 Right now I have all my mappings as hbm.xml. I want to switch dynamically the type of Id generator for certain entities from 'identity' to 'assigned' at runtime (application start). This is because I need to support importing data from previous system and keep existing ids. Is this possible? How? 回答1: The generator is part of the mappings, so you need to change the mappings before creating the session factory. This is easy to do with Fluent or ConfORM. It's possible to change XML mappings

NHibernate skips certain properties to update, possible?

≡放荡痞女 提交于 2019-12-25 08:57:42
问题 I defined my entities with bunch of columns and created mapping. public class PurchaseRecord { public virtual int? Id { get; set; } public virtual DateTime? PurchasedDate { get; set; } public virtual string Comment { get; set; } public virtual IList<PurchaseRecordExtendedProperty> ExtendedPropertyValues { get; set; } public class PurchaseRecordMap : ClassMap<PurchaseRecord> { public PurchaseRecordMap() { Table("PurchaseRecords"); Id(x => x.Id, "RecordID").GeneratedBy.Identity(); Map(x => x

NHibernate Queryover - Is there any way of getting better SQL out of nHibernate when retrieving this object plus collections graph?

╄→гoц情女王★ 提交于 2019-12-25 08:48:42
问题 We have a situation where we are trying to retrieve a couple of levels deep for an object graph using QueryOver. So if our top level is ParentEntity and our children are ChildEntitysA, ChildEntitysB and ChildEntitysC then we have something like the following code to retrieve our graph. var query = session.QueryOver<ParentEntity>(() => pAlias).Where(() => pAlias.Id == key).Future<ParentEntity>(); var queryA = session.QueryOver<ParentEntity>(() => pAlias).Left.JoinAlias(x => x.ChildEntitysA, ()

Eager loading with Linq query with restriction on details

 ̄綄美尐妖づ 提交于 2019-12-25 08:41:26
问题 How can I write a query with the build-in linq provider of NHibernate including eager loading and restrictions on the details? For example public class Library { public Library() { Books = new List<Book>(); } public virtual int Id { get; set; } public virtual string Name { get; set; } public virtual IList<Book> Books { get; protected internal set; } } public class Book { public Book() { Pages = new List<Page>(); } public virtual int Id { get; set; } public virtual Library Library { get; set;

What did I get wrong, DI or Design, and how should I go about it?

北战南征 提交于 2019-12-25 07:58:52
问题 To make a long story short, the application that I am currently writing ought to impersonate the current logged in user. It's an application to manage information inquiries. Because of NHibernate.ISessionFactory not allowing more flexibility at the level of its connection string, I need to build the connection dynamically using the current user credentials. (By the way, I'm not complaining against NH, it's a wonderful that I use on each project.) So, I need to force authentication at start up

Upgraded NHibernate and FNH DLLs - now getting “No persister” exceptions

房东的猫 提交于 2019-12-25 06:52:46
问题 I'm trying to upgrade my FNH Automapping project to the latest versions of NHibernate and Fluent NHibernate (NH 3.2 and FNH 1.3), but now I get a "no persister" exception on a derived class (though the base class still seems to be persisted properly). This derived class Automapped fine with the old dlls (FNH 1.0, NH 2.1.2) - I have not changed my mapping logic or these classes in any way. I upgraded my project by just copying the new dlls over the old ones, and deleting references to dlls

Keep an nihbernate session open forever?

巧了我就是萌 提交于 2019-12-25 05:33:11
问题 I am using quartz and nhibernate and ran into a problem. Normally I have all my nhibernate sessions close on finish of a web request but I have a scheduler that starts on application start and I need to pass in a nhibernate session that I think should never be closed. I am unsure how to do that. Ninject public class NhibernateSessionFactoryProvider : Provider<ISessionFactory> { protected override ISessionFactory CreateInstance(IContext context) { var sessionFactory = new

Keep an nihbernate session open forever?

冷暖自知 提交于 2019-12-25 05:33:08
问题 I am using quartz and nhibernate and ran into a problem. Normally I have all my nhibernate sessions close on finish of a web request but I have a scheduler that starts on application start and I need to pass in a nhibernate session that I think should never be closed. I am unsure how to do that. Ninject public class NhibernateSessionFactoryProvider : Provider<ISessionFactory> { protected override ISessionFactory CreateInstance(IContext context) { var sessionFactory = new

Nhibernate mapping - User and Friends

不羁岁月 提交于 2019-12-25 05:13:08
问题 I am trying a social network type scenario using Nhibernate as my ORM. I have a User table and a Friend table. User Table ---------- UserID FirstName LastName Email Friend Table ------------- UserID FriendUserID AddedDateTime This means the in the Friend Table it could have many to many records like A - B (A initiated a friend request to B, accepted) A - C (A initiated a friend request to C, accepted) B - C D - A (D initiated a friend request to A, accepted) B - E How can I have a Nhibernate

unique in .hbm.xml file not raising exception

≯℡__Kan透↙ 提交于 2019-12-25 04:56:19
问题 I am having the following in my .hbm.xml file <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Core.Domain.Model" assembly="Core"> <class name="Category" table="Categories" dynamic-update="true"> <cache usage="read-write"/> <id name="Id" column="Id" type="Guid"> <generator class="guid"/> </id> <property name="Name" length="100"> <column name="Name" unique="true" index="IX_Category"/> </property> </class> </hibernate-mapping> I am having