nhibernate

Minimal and correct way to map one-to-many with NHibernate

柔情痞子 提交于 2019-12-27 11:47:08
问题 I am new to NHibernate and C#, so please be gentle! I have the following two NHibernate entities: Employee { private long _id; private String _name; private String _empNumber; private IList<Address> _addresses; //Properties... } and Address { private long _id; private String _addrLine1; private String _addrLine2; private String _city; private String _country; private String _postalCode; //Properties } and they have a one-to-many relationship from Employee to Address (each employee can have

NHibernate + fluent mapping + NLog = No mapped documents found in assembly

落爺英雄遲暮 提交于 2019-12-25 18:44:09
问题 I've successfully used the CommonLogging layer in NHibernate to log its internal messages using NLog for previous projects which were using hbm.xml files. I'm now switching to fluent mapping, and the NHibernate logs now only contain one line: [Log entry: Warn] 2019-02-01 13:30:42.5537 No mapped documents found in assembly: <assembly name> I also tried to move the nhibernate-logger configuration directive from the App.config file to the code, just after configuring the mapping – and I'm

NHibernate parent-childs save redundant sql update executed

痞子三分冷 提交于 2019-12-25 16:40:01
问题 I'm trying to save (insert) parent object with a collection of child objects, all objects are new. I prefer to manually specify what to save\update and when so I do not use any cascade saves in mappings and flush sessions by myself. So basically I save this object graph like: session.Save(Parent) foreach (var child in Parent.Childs) { session.Save(child); } session.Flush() I expect this code to insert Parent row, then each child row, however NHibernate executes this SQL: INSERT INTO PARENT...

Allowing partially trusted callers security exception is been thrown althought running on Full trust mode

為{幸葍}努か 提交于 2019-12-25 16:08:43
问题 While developing using ASP.net 2.0 (C#) and NHibernate 2.1.0 I am getting the error: System.TypeInitializationException: The type initializer for 'NHibernate.ByteCode.LinFu.ProxyFactory' threw an exception. ---> System.Security.SecurityException: That assembly does not allow partially trusted callers. This error is been thrown only in the production server (a web hosting company) and in my development environment everything is fine. I also ran this code below on the production server to see

Spring.NET with NHibernate and quartz transaction (global transaction manager)

家住魔仙堡 提交于 2019-12-25 12:13:46
问题 I want to use Global transaction manager at my service layer. eg. namespace AssemblyName.Core.Service.Implementation { public class DemoService { public void demo() { save(model); //This is nHibernate transaction SchedulerManager.GetInstance.save(id); //This is related to quartz. } } } What should I use? If I used TransactionScope() then it is giving me error as NHibernateTransaction can't be committed. I have used <object id="transactionManager" type="Spring.Data.NHibernate

Relationships fixup in EntityFramework vs NHibernate

情到浓时终转凉″ 提交于 2019-12-25 12:05:31
问题 I have been experimenting with Entity Framework 4.4, NHibernate 3.3.1.4000 and SQL Server and I have noticed a difference when it comes to fixing up the relationships when you commit your changes, and I was wondering what is the best practice or if I'm doing something wrong. Here's what I tested. I have a classic Parent linked to n Children. I have 2 parents in the database with 20 children each. I load both parents, and I take the first child of the first parent and assign that child the

Relationships fixup in EntityFramework vs NHibernate

删除回忆录丶 提交于 2019-12-25 12:05:04
问题 I have been experimenting with Entity Framework 4.4, NHibernate 3.3.1.4000 and SQL Server and I have noticed a difference when it comes to fixing up the relationships when you commit your changes, and I was wondering what is the best practice or if I'm doing something wrong. Here's what I tested. I have a classic Parent linked to n Children. I have 2 parents in the database with 20 children each. I load both parents, and I take the first child of the first parent and assign that child the

Cast an IList to an IList<t> using dynamic instantiation

纵然是瞬间 提交于 2019-12-25 12:04:51
问题 I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name join name.Origin origin") .SetFirstResult(skip) .SetMaxResults(pageSize); Running this I get the following error:- Unable to cast object of type 'NHibernate.Impl

Cast an IList to an IList<t> using dynamic instantiation

会有一股神秘感。 提交于 2019-12-25 12:04:41
问题 I am try to convert the following NHibernate query using dyanmic instantiation into an IList<t> rather than an IList. IList<AllName> allNames = (IList<AllName>)Session.CreateQuery( @"select new AllName( name.NameId, name.FirstName, origin.OriginId, origin.Description, name.Sex, name.Description, name.SoundEx ) from Name name join name.Origin origin") .SetFirstResult(skip) .SetMaxResults(pageSize); Running this I get the following error:- Unable to cast object of type 'NHibernate.Impl

How to get page number by entity with NHibernate?

拈花ヽ惹草 提交于 2019-12-25 10:20:11
问题 I have a paging worked with NHibernate: public IEnumerable<Answer> GetAnswers(int page, int pageSize) { return HibernateTemplate.Execute( session => { var criteria = session.CreateCriteria(typeof(Answer)); return criteria .SetFirstResult((page - 1) * pageSize) .SetMaxResults(pageSize).List<Answer>(); } ); } Now my task is to determine on which page concrete Answer object is placed. How can i do it? Does nhibernate provide some info like index of row in result set? 回答1: NHibernate HQL offers