nhibernate

Any real use for table-per-concrete-class with implicit polymorphism?

*爱你&永不变心* 提交于 2020-01-24 14:07:38
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

Any real use for table-per-concrete-class with implicit polymorphism?

浪子不回头ぞ 提交于 2020-01-24 14:05:09
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

Any real use for table-per-concrete-class with implicit polymorphism?

假如想象 提交于 2020-01-24 14:04:04
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

Generate a business key

丶灬走出姿态 提交于 2020-01-24 12:53:56
问题 What is the best way to generate a unique number for a business key? In the example below, our customer wants a number (OrderNumber) they can use to refer to an Order. <class name="Order"> <id name="Id" ... /> <property name="OrderNumber" column="order_number" /> </class> 回答1: I've found that the best way to perform these tasks is to write them in code and not leak them into the data layer. I don't let NHibernate calculate it. I treat this concept as a fully fledged feature of the application

Generate a business key

孤者浪人 提交于 2020-01-24 12:53:47
问题 What is the best way to generate a unique number for a business key? In the example below, our customer wants a number (OrderNumber) they can use to refer to an Order. <class name="Order"> <id name="Id" ... /> <property name="OrderNumber" column="order_number" /> </class> 回答1: I've found that the best way to perform these tasks is to write them in code and not leak them into the data layer. I don't let NHibernate calculate it. I treat this concept as a fully fledged feature of the application

Hibernate cascade delete on a bag

偶尔善良 提交于 2020-01-24 11:27:12
问题 Having built most of my DAL using NHibernate, I've now discovered that the SQL Server's Cascade On Delete rules also need to be taken into account in my HBM files too. I've been using bags for all my collections, but there doesn't seem to be a way to add a cascade="delete" attribute to a bag. I can change all my bags to sets, but that appears to mean I have changing all my IList<>s on my models to PersistentGenericSet<>s, which I don't really fancy doing. Any advice? Anthony 回答1: There are

How to delete version records of a content item in Orchard?

送分小仙女□ 提交于 2020-01-24 10:19:12
问题 I have a Orchard CMS running that is tied to a user synchronization. This sync updates each user overnight and the code begins with ... = mContentManager.Get<Orchard.Users.Models.UserPart>(lOrchardUser.ContentItem.Id, Orchard.ContentManagement.VersionOptions.DraftRequired); As you can see VersionOptions.DraftRequired is passed to the Get() method with creates a new draft each time the user is synchronized. It's not intended to create a new draft here so i changed it to VersionOptions

nhibernate and transactionscope transaction aborted spontaniously

落爺英雄遲暮 提交于 2020-01-23 20:28:25
问题 I am working with Nhibernate and TransactionScope in a large application. The application is supposed to modify 3 databases and support a distribuited transaction across them. This is the code that I call each time I want to query or execute some sql on the database within the distribuited transaction: IDbConnection connection = new SqlConnection(connectionString); connection.Open(); ISession session = SessionFactory.OpenSession(connection); And this is the code called whenever after the

Linq for NHibernate - filtering on <many-to-one> foreign key causes extra lookup

ぃ、小莉子 提交于 2020-01-23 17:55:09
问题 Trying out Linq for NHibernate and first noticed this: var list1 = (from ut in session.Linq<UserThings>() where ut.User.ID == 10 select ut).ToList(); var list2 = session.CreateCriteria(typeof (UserThings), "ut") .Add(Expression.Eq("ut.User.ID", 10)) .List<UserThings>(); This first query will join on the 'User' table, but the second will not. Somehow the second knows that UserID is the foreign key and that it doesn't need to perform the join to filter. 回答1: The best piece of advice anyone will

Passing an expression to a method in NHibernate results in Object of type 'ConstantExpression' cannot be converted to type 'LambdaExpression'

Deadly 提交于 2020-01-23 16:16:53
问题 This problem occurs in both NHibernate 2 and 3. I have a Class A that has a member set of class B. Querying the classes directly executes nicely. But when I pass one of the expressions involving class B into a method I get the following error: System.ArgumentException: Object of type 'System.Linq.Expressions.ConstantExpression' cannot be converted to type 'System.Linq.Expressions.LambdaExpression'. As far as I can see I am passing the exact same expression into the Any() method. But for some