nhibernate

How to cascade Save with CompositeId in NHibernate?

纵然是瞬间 提交于 2019-12-23 18:01:49
问题 I have a simple three table DB with many-to-many relation. A(id, Name) B(id, Name) AB(AId, BId) references A and B The corresponding classes: public class A { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class B { public virtual int Id { get; set; } public virtual string Name { get; set; } } public class AB { public virtual A A { get; set; } public virtual B B { get; set; } public override bool Equals(object obj) { /* routine */ } public override int

NHibernate QueryOver SQLFunction in where clause

天大地大妈咪最大 提交于 2019-12-23 17:53:04
问题 I would like to query a table having multiple rows, each with a timestamp with data coming at ten minute intervals. I would like to find the beginning of any missing data, which is where there is not a timestamp equaling the next ten minute interval, like this: select a.[timestamp] from [table] as a where not exists (select 1 from [table] as b where a.[id] = b.[id] and b.[timestamp] = dateadd(mi, 10, a.[timestamp])) order by a.[timestamp] I have this so far, but I fail to see how to build the

get SQL query from NHibernate criteria, before the criteria executes

蹲街弑〆低调 提交于 2019-12-23 17:47:17
问题 I have a NHibernate criteria, from which I need to get the SQL query. I tried the various methods from here. However, the query which I get does not have the parameters in it(it has a '?' in place of that, just like mentioned over here and here). Also, at least one thing that does not work is criteria.setMaxResults(n). I also tried NHibernate interceptors. However, the query which I get in the OnPrepareStatement(sql) also does not have the parameters. Is there any other way of getting the sql

Using a subquery for a column with QueryOver

左心房为你撑大大i 提交于 2019-12-23 17:33:48
问题 I'm trying to get something similar to the SQL below via QueryOver: SELECT docs.*, (SELECT TOP 1 eventDate from events WHERE id=docs.id AND type=4 ORDER BY eventDate DESC) as eventDate FROM documents as docs WHERE doc.accountId = ... I've got close with a projection, however I'm not sure how to get the entire documents table back. Documents has a one-to-many relationship with Events, I don't want to outer join as it will bring multiple results, and an inner join may not bring back a row: var

Domain Driven Design: Aggregate roots with large collections

左心房为你撑大大i 提交于 2019-12-23 17:33:41
问题 I was wondering how I would handle aggregate roots that contain collections with a lot of entities. Like: public class AggregateRoot { public ICollection<Child> Children { get; set; } // 10.000 entities } How would I query the child collection to get specific children? I am using Nhibernate btw. 回答1: You can use Nhibernate's collection filters for this, see this similar question for examples. 来源: https://stackoverflow.com/questions/3958107/domain-driven-design-aggregate-roots-with-large

entity -> interface relationship, how to map

十年热恋 提交于 2019-12-23 17:23:28
问题 I’m trying to develop some basic web app. I will post question with only two entities Article and Image. One article has many images, and one or more images belong to only one article. Every article implements interface IArticle and abstract class ArticleBase. ArticleBase defines only common properties for each article but child articles can have more properties beside those defined in ArticleBase. So I have ( IArticle , ArticleBase , ArticleComputer , ArticleCar ) public abstract class

nhibernate envers: auditing an entity already in production

一笑奈何 提交于 2019-12-23 17:14:05
问题 We have an application that is already in production and it is using Envers to do auditing. Now we are going to release an update in which we audit a new kind of entity. However this entity already exists in the production environment, only it was not audited so far. We have tried in a test environment containing existings records, and it crashes upon saving because Envers cannot find a previous revision for the entity being saved. What is the approach to takle this issue ? It would be great

Nhibernate: restriction with sum of 2 columns

江枫思渺然 提交于 2019-12-23 17:08:05
问题 Can I create this sql query using HNibernate Criteria: Select * from Table1 where Column1 > (Column2 + Column3) All 3 columns are int32. Thanks 回答1: Well, after reading for the n-th time a question with this exact problem i decided to write an implementation that doesn't include writing SQL. You can check the implementation at http://savale.blogspot.com/2011/04/nhibernate-and-missing.html with which you can write: criteria.Add( Restrictions .GeProperty("Prop1", new

one of the fields is count(*) NHibernate

大兔子大兔子 提交于 2019-12-23 16:32:54
问题 Can I do mapping to query like this : select id,name,address,(select count(*) from account where record_id=id ) as counter from data where id = :id Currently , I'm using a native SQL . class person { public virtual long Id{get;set;} public virtual string Name{get;set;} public virtual string Address{get;set;} public virtual long Counter{get;set;} } mapping : <property name="Counter" formula="(select count(*) from account where record_id=id )" type="long"/> 回答1: Yes, you should use formula.

one of the fields is count(*) NHibernate

我的未来我决定 提交于 2019-12-23 16:32:34
问题 Can I do mapping to query like this : select id,name,address,(select count(*) from account where record_id=id ) as counter from data where id = :id Currently , I'm using a native SQL . class person { public virtual long Id{get;set;} public virtual string Name{get;set;} public virtual string Address{get;set;} public virtual long Counter{get;set;} } mapping : <property name="Counter" formula="(select count(*) from account where record_id=id )" type="long"/> 回答1: Yes, you should use formula.