fluent-nhibernate

NHibernate HQL Inner Join (SQL Server,Visual C#)

谁说胖子不能爱 提交于 2019-12-02 15:19:31
问题 I want to using HQL with inner Join. But, a query syntax exception is thrown. This is my C# code: string sqlQuery = "Select fq FROM Answers as fq INNER JOIN Questions as q " + " on fq.questionId=q.questionId"; IList Result; int count = 0; try { using (ISession session = ConnectionModule.OpenSession()) { IQuery query = session.CreateQuery(sqlQuery); session.CreateCriteria(typeof(Answers)); Result = query.List(); } } catch(Exception ex) { MessageBox.Show(ex.Message+"\n"+ex.InnerException); }

NHibernate Criteria with Distinct Parent Load All Children?

一个人想着一个人 提交于 2019-12-02 14:44:59
问题 I have a parent child relationship where I want to return only one parent and load all the children. I am using criteria because it is a dynamic query. var messageQueueId = this.GetPropertyName<MessageQueue>(x => x.Id); var query = _sessionManager.Session.CreateCriteria<MessageQueue>(QUEUE_ALIAS); query.SetFirstResult(_pageOffset); query.SetMaxResults(_pageSize); query.Add(Restrictions.In(messageQueueId, _messageQueueIds)); query.List<MessageQueue>(); This returns the parent (MessageQueue)

Fluent NHibernate 1.1: when multiple column name mappings are used on different classes

和自甴很熟 提交于 2019-12-02 13:37:00
问题 Suppose I have this (simplified) Class Cliente Id(v => v.numero_cliente, "numero_cliente") HasMany(v => v.Acionamentos).Cascade.All().LazyLoad() Class Movimentacao References(v => v.Cliente, "id_Fornecedor") Class Acionamento References(v => v.Cliente, "numero_cliente") Fluent nHibernate will generate wrong SQL, for example: If i try to get Acionamentos,then it will throw an incorrect SQL: SELECT * FROM Acionamentos WHERE id_Fornecedor =p0 But on my Acionamento Mapping i set an reference to a

Nhibernate QueryOver JoinAlias UnRelated Entity

左心房为你撑大大i 提交于 2019-12-02 13:19:38
问题 I have an issue in NHibernate regarding a left join using "JoinAlias" when the result query SQL that I am looking for is this : "select * from EntityA T1 left join EntityB T2 on T2.EntityAId=T1.id" And in NHibernate I have this but doesn't work: var query = _session.QueryOver(() => EntityA) .Left.JoinAlias(() => EntityA, () => EntityB.EntityA) In NHibernate EntityA doesn't reference to EntityB but EntityB as a reference to EntityA . public class EntityA { public int Id {get;set;} } public

NHibernate: Map one class to two identical tables

一个人想着一个人 提交于 2019-12-02 12:02:26
I need to map one entity to two tables (Invoice and InvoiceHistory). It's not up to me to merge the two database tables in one and add a status column to differentiate them. The two tables have the exact same structure, but, as the name says, InvoiceHistory keeps a history of old invoices whereas Invoice stores active invoices. (the exact entity is not invoice but I am not allowed to disclose details plus I don't think they would be relevant anyway). Create another entity which inherits the first entity you created and does nothing else. You can then map the new entity to InvoiceHistory, while

Nhibernate Flush causing Updates where there should be none

蹲街弑〆低调 提交于 2019-12-02 12:00:17
问题 I am using the Repo pattern, and I have set up tests to replicate my a HTTP request coming in and then causing dispose on a unit of work once a test has completed. It appears that after executing a HQL statement, and then calling displose (which in turn calls flush) that it is causing an update across various elements. Very bizzare - has anyone come across this before? Here is my HQL statement and it's execution: _session.CreateQuery("select distinct t from TaskEntity as t").List<T>() I've

NHibernate Prevent Lazy Loading of unmatched reference

安稳与你 提交于 2019-12-02 11:06:13
问题 I have quite a problem with NHibernate. I have a reference from Table1 to Table2, and I want NHibernate to, when a corresponding record is not found in Table2, to not then issue a SELECT statement against Table2, to, I don't know, make really really sure that it actually isn't there. I've tried adding modifiers like .LazyLoad(Laziness.False) and .NotFound.Ignore() to my reference, but NHibernate gaily ignores my commands with extreme prejudice, issuing its select and breaking my code. 回答1: It

NHibernate Fluent Add external Assembly mappings

。_饼干妹妹 提交于 2019-12-02 10:51:46
I have a project with my mappings and entities stored in other class libraries and NHibernate layers in another project. In my testing project I would like to add these mapping via fluently configure... Mappings... via assebly and not individually. In my code below you can see I added just one entity.. But I would like to configure it to scan my other assemblies. I am sure I am just missing the obvious here.. any pointers would be greatly appreciated... [Test] public void Can_generate_schemaFluently() { var cfg = new Configuration(); cfg.Configure(); Configuration configuration = null;

How to map it? HasOne x References

你说的曾经没有我的故事 提交于 2019-12-02 10:13:20
I need to make a mapping One by One, and I have some doubts. I have this classes: public class DocumentType { public virtual int Id { get; set; } /* othes properties for documenttype */ public virtual DocumentConfiguration Configuration { get; set; } public DocumentType () { } } public class DocumentConfiguration { public virtual int Id { get; set; } /* some other properties for configuration */ public virtual DocumentType Type { get; set; } public DocumentConfiguration () { } } A DocumentType object has only one DocumentConfiguration, but it is not a inherits, it's only one by one and unique,

Join Unrelated tables in Fluent Nhibernate with QueryOver or CreateCriteria

拈花ヽ惹草 提交于 2019-12-02 09:14:23
I have tables : tableAnnual - AnnualAmount, AnnualCurrency. creationDate, Id tableMonthly - MonthlyAmount, MonthlyCurrency, creationDate, Id tableSharevalue - CurrentSharevalue, creationDate, Id tableMiscDetails - clientType, clientName, MarketValueAmount, creationDate I have now to do the following select with NHibernate and QueryOver: Select tableAnnual.AnnualAmount, tableAnnual.AnnualCurrency, tableMonthly.MonthlyAmount, MonthlyAmount.MonthlyCurrency, tableSharevalue.CurrentSharevalue, tableMiscDetails.clientType, tableMiscDetails.clientName, tableMiscDetails.MarketValueAmount from