nhibernate-criteria

NH QueryOver - use properties of main query in subquery

孤街浪徒 提交于 2019-12-20 03:51:08
问题 I am trying to convert following SQL to QueryOver: Select 1 From myTable mt Where mt.ForeignKey in (select ID from otherTable ot where ot.ID = R.ID) I want to use this subquery inside an EXISTS / NOT EXISTS statement like: select * from table R where .... AND EXISTS (query above) Currently I have something like: mainQuery.WithSubquery.WhereExists(QueryOver.Of<myTable>() .Where(mt => mt.ForeignKey) .WithSubquery.IsIn(QueryOver.Of<otherTable>().Where(c => c.Id == R.SomeId))); I created this

Using SQL CONVERT function through nHibernate Criterion

筅森魡賤 提交于 2019-12-17 20:53:16
问题 I have a sql view, in which the data type of every column is string , for use with the jquery datatables plugin. One of the columns contains a uk format date dd/mm/yyyy. This column needs to remain a string to work with the keystroke filtering of the plugin, however for sorting it needs to be treated as a date. I am using nhibernate criteria to create the sql query and I want to generate the following order by clause, as this orders the dates correctly order by CONVERT (datetime, DateOfBirth,

NHibernate QueryOver with leftjoins

纵然是瞬间 提交于 2019-12-13 00:36:30
问题 This thing is keeping me busy for days and I hope someone of the NHibernate gurus can help me out. I've got a query set up which is working in SQL Server and I want to get the same in NHibernate. But all my tries (did a lot of googeling and browsing in stackoverflow) failed so far. Here's the query: Select j.id, j.title, j.company, jt.name as category, loc.city, je.is_assigned, FROM job j LEFT JOIN location loc ON loc.id = j.location LEFT JOIN job_tag jt ON jt.job = j.id and jt.name in

NHibernate Filtered Child Collection Lazy Loaded even with eager fetch specified

亡梦爱人 提交于 2019-12-12 08:56:50
问题 Im trying to find out why a child collection is being returned without filtering even when eager loading the collection and the generated SQL is correct. The fluent mappings for the classes are: public class OptionIdentifierMap : ClassMap<OptionIdentifier> { public OptionIdentifierMap() : base("OptionIdentifier") { //Id Mapping Removed HasMany<OptionPrice>(x => x.OptionPrices) .KeyColumn("OptionIdentifier_id") .Cascade.None(); } } public class OptionPriceMap : ClassMap<OptionPrice> { public

NHibernate: Query by discriminator on association

ぃ、小莉子 提交于 2019-12-12 04:38:32
问题 My question is similar to this question. But I want to query by the discriminator of a child entity associated with a one-to-one relationship, and without knowing the exact discriminator value, i.e., by type not by string. Given an hbm like: <class name="Parent" table="ParentTable"> <id name="Id"> <generator class="guid.comb" /> </id> <one-to-one name="Child" class="IChild" property-ref="Parent" cascade="all" /> </class> <class name="IChild" table="ChildTable" abstract="true"> <id name="Id">

To insert a value in foreign key in mvc3 nihibernate

佐手、 提交于 2019-12-12 03:21:12
问题 I am making an application named Question-Answer Forum using nhibernate in mvc3 One the first page i have a list of questions displayed as link and when i click on the click it directs me to the answers page. Table Structure: Questions Table: QuestionID int Question nvarchar(255) Created_Date datetime Modified_Date datetime Created_By int Modified_By int Deleted nchar(1) Answers Table: Id int Answer nvarchar(255) Created_Date datetime Modified_Date datetime Created_By int Modified_By int

NHibernate comparison constraint to a coalesced date

纵然是瞬间 提交于 2019-12-11 12:15:37
问题 There is a great Q/A to prefacing this question here: NHibernate COALESCE issue I need to be able to compare a date object to a date value from within an inner join. The unfamiliar territory here has been the implementation of this COALESCE along with the date LT constraint Here is my current SQL query SELECT DISTINCT Sites.* FROM Sites INNER JOIN Sites_WF_Info ON Site_Key = SiteWFInfo_Site_Key AND SiteWFInfo_Effective_Date <= @today AND @today <= SiteWFInfo_End_Date INNER JOIN Profit_Centers

Catching the NHibernate generated SQL and amending before running

会有一股神秘感。 提交于 2019-12-11 03:23:35
问题 Is it possible to obtain the sql that would be created by nhibernate in your code without actually running it? I have a complex criteria object that I have built through the criteria API. This criteria object forms the base of various select statements. I can then take this base and add on the additional criteria I require in differing scenarios throughout my application. I now have the need to add a having clause to one of my select statements and apparently this is not an option using the

Fluent Nhibernate - selecting specific column and count query with group by

安稳与你 提交于 2019-12-10 21:08:09
问题 I'm having some trouble excuting a query in fluent nhibernate. I have a table : Books with the following columns: ID, NAME, YEAR, BOOK_TYPE, AUTHOR_ID I want to excute the following sql query in Fluent NHibernate: SELECT BOOK_TYPE, COUNT(*) FROM BOOKS GROUP BY BOOK_TYPE 回答1: So called Fluent-NHibernate is just a mapping extension. To get data we need NHibernate built n querying features: ICriteria , QueryOver or even a LINQ . Based on the documentation we can use projections for the above

Nhibernate n+1 with ternary relationship. Want the middle entity in the ternary

混江龙づ霸主 提交于 2019-12-10 17:40:34
问题 I'm having a huge issue with nhibernate n+1 and nothing I try seems to fix the problem. Nhibernate profiler still shows n+1 selects hitting the database. Here's my model: public class CustomerGroup : CoreObjectBase { public virtual long GroupId { get; set; } public virtual Site Site { get; set; } public virtual IList<Customer> Customers { get; set; } public virtual string Name { get; set; } public virtual string DisplayName { get; set; } public virtual CustomerGroupStatus Status { get; set; }