nhibernate-criteria

NHibernate converting string parameters to nvarchar instead of varchar. How can I stop this?

天涯浪子 提交于 2019-12-05 21:15:58
I have a class mapped to a view and am searching on first and last names in order to search for patient records. The view ultimately looks at the first and last name fields on the patient table (possibly others as well depending on input). When the criteria converts to SQL, it's entering my strings as nvarchar parameters. I've already used type="AnsiString" and length="50" on my mapping, but it still is converting these to nvarchar, which is causing a performance hit on my query. <class name="PatientSearchResult" table="vw_PatientSearch" mutable="false" > <id name="Id" type="Guid" column=

Set TimeOut Expired in NHibernate

耗尽温柔 提交于 2019-12-05 08:32:02
I have a stored procedure in sql server 2008 R2 which was working fine, but suddenly it throws an exception of TimeOut Expiration. BmDaoSession.CreateSQLQuery("exec SP_Name @Param1 = '" + clientCode + "', @Param2 ='" + existingDatabase + "', @Flag='" + flag + "'").ExecuteUpdate(); I am using the above NHibernate command to call my SP. My question is how Can I set the TimeOut Expiration in NHibernate. Thanks Najera Just add fluently SetTimeout method: BmDaoSession.CreateSQLQuery("exec SP_Name @Param1 = '" + clientCode + "', @Param2 ='" + existingDatabase + "', @Flag='" + flag + "'") .SetTimeout

NHibernate - easiest way to do a LIKE search against an integer column with Criteria API?

。_饼干妹妹 提交于 2019-12-05 01:30:55
I'm trying to do a like search against an integer column, what I need to do is actually cast the column to a varchar and then do the like search. Is this possible? what's the easiest way to do this using the Criteria API? var search = "123"; criteria.Add(Restrictions.Like("Number", "%" + search + "%")) If Number were a string, then it would be easy : .Add(Restrictions.Like("Number", "some_value",MatchMode.Anywhere)) Since you have a number, NHibernate will check the type of Number and if you give it a string it will throw an exception. Not sure why the NH team didn't provide an overload with

Fluent NHibernate and filtering one-to-many relationship on query requiring multiple joins?

被刻印的时光 ゝ 提交于 2019-12-04 12:23:26
I recently got started with NHibernate and am having some trouble implementing the domain model outlined further down. What I'm looking for is a way to filter the relationship between an Item and it's ItemData collection on specific DataStores. DataStores are either global, in which case they are always returned, or specific to a user identity (based on application instance). In SQL this can be accomplished using a simple query: SELECT * FROM Items i INNER JOIN ItemData id ON (i.ItemId=id.ItemId) LEFT OUTER JOIN Users u ON (id.UserId=u.UserId) LEFT OUTER JOIN DataStore ds ON (id.DataStoreId=ds

NHibernate Filtered Child Collection Lazy Loaded even with eager fetch specified

这一生的挚爱 提交于 2019-12-04 12:10:19
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 OptionPriceMap() : base("OptionPrice") { //Id Mapping removed References(x => x.Option) .Column(

Nhibernate count distinct (based on multiple columns)

杀马特。学长 韩版系。学妹 提交于 2019-12-03 18:10:00
问题 Basically, i have been trying to do this (count distinct based on two columns): select count(distinct(checksum(TableA.PropertyA, TableB.PropertyB))) from TableA left outer join TableB on TableA.TableBId = TableB.Id where PropertyA like '%123%' Been googling on how to do this but with no luck. Tried this, but never actually worked. This does not count distinctly based on the two properties from two tables: var queryOver = c.QueryOver<TableA>(); TableB tableBAlias = null; TableA tableAAlias =

Querying with nHibernate where todays date is between publishDate and Expiry date

假如想象 提交于 2019-12-03 12:52:35
I am trying to figure out how to best query in NHibernate so that the returned results are between for entries where todays time is >= PublishDateTime and <=ExpiryDateTime The expiry date can be null so I need to allow for that. I found a couple of examples here and here but they seem to work in a different way and accept 2 values and compare to one DB field. I want the other way wrong really. Query so far: var query = _session.CreateCriteria<Message>() .AddOrder(Order.Desc("PublishedDateTime")) .List<Message>(); return query; Any suggestions would be greatly received! Easiest Linq query:

NHibernate - Wrong Columns on Queries

戏子无情 提交于 2019-12-03 02:15:41
I'm getting an intermittant problem with NHibernate where it generates a query for an entity, but replaces one of the columns with a column from completely different (and unrelated) entity. It only ever replaces a single column, and is generally solved by restarting the application (though sometimes it takes a couple of attempts). ASP.NET application (.NET 4.0) SessionFactory created during Application_Start NHibernate 3.3.1- All mappings/configuration done via Mapping By Code Using Nhibernate Criteria Any input on this would be much appreciated! Entity public class LiquiditySourceItem :

Make a SQL Query to Nhibernate

烂漫一生 提交于 2019-12-02 10:11:37
How do I get this SQL query to Nhibernate? SELECT Customer.name FROM Company INNER JOIN Customer ON Company.CompanyId = Customer.CompanyId where CompanyId = 2 If you are familiar with LINQ it is very very simple, you have to directly access the reference filed just as an entity. and you will get the properties of that entity and so on you can access till the nth node. Nhibernate will take care of reference fields as entities.. //Here is the sample this may work //CustomerList is a nhibernate entity list. //CompanyId is also an entity which is a reference to the CompanyId of Company table. //

NH QueryOver - use properties of main query in subquery

末鹿安然 提交于 2019-12-02 06:23:16
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 query as a subquery which I want to connect to the main query. The problem is that the table aliased as R