nhibernate

Nhibernate Multiple Database in One Transaction

眉间皱痕 提交于 2019-12-24 12:45:28
问题 My program access to 2 databases and do some DB works. I want to do these works in one transaction and if one of them get any error, also another one should NOT be committed. Here where I am right now, the simple code of a program. using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { using (var session1 = NHibernateHelper.OpenSession1()) { using (var session2 = NHibernateHelper.OpenSession2()) { using (var trnx1 = session1.BeginTransaction

Delete Cascade is not working with NHibernate

自作多情 提交于 2019-12-24 12:25:04
问题 I have a table Communication which has a reference to PersonCompany. In the mapping for PersonCompany i have defined a Cascade-Delete for this reference: this.HasMany(x => x.Communications) .AsSet() .KeyColumn("PersonCompanyId") .Fetch.Select() .Inverse() .Cascade.Delete(); But when I now execute the fallowing HQL-Query: var sql = "delete from PersonCompany where Person.Id in (:idList) or Company.Id in (:idList)"; with var query = NHibernateHelper.CurrentSession.CreateQuery(sql); query

Unidirectional parent-child association not null

我只是一个虾纸丫 提交于 2019-12-24 12:13:48
问题 I have a class structure which is akin to a PurchaseOrder (parent) and PurchaseOrderLine (child) pattern, where the order lines will only be saved to the DB by saving the parent PurchaseOrder and will only ever be accessed via the parent too. The DB has PurchaseOrderLine.PurchaseOrder set to not permit null values. It seems from searching through the web that it is not possible to have a uni-directional association from PurchaseOrder via an IList property without having to have a property on

wont save to database with guid as id- fluent-nhiberate

不羁岁月 提交于 2019-12-24 11:56:23
问题 i got problems with saving when i use Guid as identifier. can anybody se what i am missing here? i create my own guid so i dont want it to be generated by database. NOTE: i have tried the guid.combo in mapping to without any success. public class Order { public virtual Guid Id { get; set; } public virtual ICollection<OrderItem> OrderItems { get; set; } public virtual User User { get; set; } public virtual DateTime? CreateDate { get; set; } public virtual DateTime? ShippedDate { get; set; }

nHibernate- a Collection which would contain only a supertype

核能气质少年 提交于 2019-12-24 11:53:03
问题 I have the following classes: class Employee { public string Name { get; set; } } class HistoricalEmployee : Employee { public DateTime TerminationDate { get; set; } } class Company { public IList<Person> CurrentEmployees { get; set; } } Employee and HistoricalEmployee are mapped using table-per-class-heirarchy strategy. When I retrieve the CurrentEmployees collection, I want it only to contain elements that are Employee, and NOT HistoricalEmployees. when an employee 'dies', they're not

nHibernate- a Collection which would contain only a supertype

二次信任 提交于 2019-12-24 11:48:21
问题 I have the following classes: class Employee { public string Name { get; set; } } class HistoricalEmployee : Employee { public DateTime TerminationDate { get; set; } } class Company { public IList<Person> CurrentEmployees { get; set; } } Employee and HistoricalEmployee are mapped using table-per-class-heirarchy strategy. When I retrieve the CurrentEmployees collection, I want it only to contain elements that are Employee, and NOT HistoricalEmployees. when an employee 'dies', they're not

FluentNHibernate and primitive type collection

北城余情 提交于 2019-12-24 11:37:41
问题 I'm having trouble persisting primitive type collection using (Fluent)NHibernate. Here's the entity and mapping: public class SomeOne { public virtual long ID { get; set; } public virtual string Name { get; set; } public virtual string Description { get; set; } public virtual Iesi.Collections.Generic.ISet<string> Foo { get; protected set; } public SomeOne() { Foo = new HashedSet<string>(); } } public SomeOneMap() { Id(x => x.ID).GeneratedBy.Identity(); Map(x => x.Name); Map(x => x.Description

Is there an alternative to ISession.Merge() that doesn't throw when using optimistic locking?

余生长醉 提交于 2019-12-24 11:29:23
问题 I've been trying to use ISession.Merge() to keep coherence between two sessions, but it fails when the merged instance has a higher Version property than the one loaded in the session (with a StaleObjectStateException). Is there an alternative method that would work when the Version fields do not match ? 回答1: Try calling: Session.Lock(string entityName, object obj, LockMode lockMode); with LockMode.Force. The remarks for that method state: This may be used to perform a version check

nhibernate group by join query

强颜欢笑 提交于 2019-12-24 10:59:01
问题 I have the following entities: public class Shift { public virtual int ShiftId { get; set; } public virtual string ShiftDesc { get; set; } public virtual IList<ShiftHistory> ShiftHistory { get; set; } } public class ShiftHistory { public virtual System.DateTime ShiftStartLocal { get; set; } public virtual System.DateTime ShiftEndLocal { get; set; } public virtual Zone Zone { get; set; } public virtual Shift Shift { get; set; } public virtual int RowId { get; set; } } public class Zone {

Lazy property loading in Nhibernate and Spring

六眼飞鱼酱① 提交于 2019-12-24 10:49:01
问题 I'm using NHibernate 2.1.2 and Spring 1.3 I have two Text columns (blobs) in one of my classes. I'm trying to use lazy="true" for the mapping of those properties but NHProfiler still shows the two columns being added to the SELECT statement when the main object is loaded. I'm using Spring.NHibernate session factory and have configured ProxyFactory with both Castle and Spring with no luck. 回答1: So far I know that's something NOT included on the version 2.1.2 According this url, lazy properties