linq-to-nhibernate

Best way to delete all rows in a table using NHibernate?

不想你离开。 提交于 2019-11-29 22:13:06
To keep my integration tests independent I remove all old data and insert new test data before each test. Is there a better way of doing this than simply querying for all entities and deleting them one by one? I have considered writing a stored proc that runs "delete from tablename ;" for each table that is to be cleared. That ought to quite a bit faster, but it would be nice to do it without doing SQL queries or calling SPs via NH. I'm using vanilla NHibernate and Linq to NHibernate. I beleive Castle Active Record has something like Foo.DeleteAll(), but I don't want to use Active Record for

Nhibernate could not resolve property exception when using QueryOver, works on QueryAll

孤者浪人 提交于 2019-11-29 09:46:38
问题 I have the following problem Basically I have the 2 snippets below: var contactAssociation = session.QueryOver<ContactAssociation>(() => contactAssociationAlias) .Where(() => contactAssociationAlias.Contact.ID == careGiverId && contactAssociationAlias.Client.ID == clientKey) .Where(() => contactAssociationAlias.AclRole.RoleName == "Care Giver") .SingleOrDefault(); and var contactAssociation = session.Query<ContactAssociation>() .Where(cr => cr.Contact.ID == careGiverId && cr.Client.ID ==

Difference between deferred execution and Lazy evaluation in C#

浪子不回头ぞ 提交于 2019-11-29 07:42:46
问题 Could you please let me know what is the exact deference between deferred execution and Lazy evaluation in C#?These two are used synonymously.Could some one please explain the difference with an example?? 回答1: In practice, they mean essentially the same thing. However, it's preferable to use the term deferred . Lazy means "don't do the work until you absolutely have to." Deferred means "don't compute the result until the caller actually uses it." In practice, when the caller decides to use

Nhibernate query for items that have a Dictionary Property containing value

假装没事ソ 提交于 2019-11-29 07:36:45
I need a way to query in Nhibernate for items that have a Dictionary Property containing value. Assume: public class Item { public virtual IDictionary<int, string> DictionaryProperty {get; set;} } and mapping: public ItemMap() { HasMany(x => x.DictionaryProperty) .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore) .AsMap<string>( index => index.Column("IDNumber").Type<int>(), element => element.Column("TextField").Type<string>().Length(666) ) .Cascade.AllDeleteOrphan() .Fetch.Join(); } I want to query all Item s that have a dictionary value of "SomeText". The following example in

How would I alter the SQL that Linq-to-Nhibernate generates for specific columns?

末鹿安然 提交于 2019-11-29 02:45:05
To take advantage of Full text indexing on MariaDB 10, I need to use this new "MATCH AGAINST" syntax in the sql string. http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match I think it would be really cool if, for certain columns only, I could override linq-to-nhibernate to change the sql it generates when I use .Where(x => FullTextIndexedStringProperty.Contains("Some word")).ToList(). Who can give me some general directions on how to get started? This will get you a very simple MATCH ... AGAINST clause. If you want to get more complex (more arguments, specifying the

Getting count with NHibernate + Linq + Future

[亡魂溺海] 提交于 2019-11-28 19:28:45
I want to do paging with NHibernate when writing a Linq query. It's easy to do something like this: return session.Query<Payment>() .OrderByDescending(payment => payment.Created) .Skip((page - 1)*pageSize) .Take(pageSize) .ToArray(); But with this I don't get any info about the total number of items. And if I just do a simple .Count(), that will generate a new call to the database. I found this answer which solved it by using future. But it uses Criteria. How can I do this with Linq? The difficulty with using Futures with LINQ is that operations like Count execute immediately. As @vandalo

Best way to delete all rows in a table using NHibernate?

我的梦境 提交于 2019-11-28 18:51:00
问题 To keep my integration tests independent I remove all old data and insert new test data before each test. Is there a better way of doing this than simply querying for all entities and deleting them one by one? I have considered writing a stored proc that runs "delete from tablename ;" for each table that is to be cleared. That ought to quite a bit faster, but it would be nice to do it without doing SQL queries or calling SPs via NH. I'm using vanilla NHibernate and Linq to NHibernate. I

How to write this linq query with Criteria or QueryOver API

﹥>﹥吖頭↗ 提交于 2019-11-28 05:37:28
问题 Is it possible to convert this code at below, written by using Query(linq) api to Criteria or QueryOver API in NHibernate? I'm using this to format data into DTO's also it works with just one round-trip to db. Note: I tried transformers.aliastobean but I can only use one transformer at a time. Is it possible to use multiple transformer in one query? from entityType in Provider.GetSession().Query<crmEntityType>() .Fetch(x => x.Association) .Fetch(x => x.Fields) .AsEnumerable() where

Nhibernate query for items that have a Dictionary Property containing value

荒凉一梦 提交于 2019-11-28 01:05:20
问题 I need a way to query in Nhibernate for items that have a Dictionary Property containing value. Assume: public class Item { public virtual IDictionary<int, string> DictionaryProperty {get; set;} } and mapping: public ItemMap() { HasMany(x => x.DictionaryProperty) .Access.ReadOnlyPropertyThroughCamelCaseField(Prefix.Underscore) .AsMap<string>( index => index.Column("IDNumber").Type<int>(), element => element.Column("TextField").Type<string>().Length(666) ) .Cascade.AllDeleteOrphan() .Fetch

How would I alter the SQL that Linq-to-Nhibernate generates for specific columns?

女生的网名这么多〃 提交于 2019-11-27 17:01:18
问题 To take advantage of Full text indexing on MariaDB 10, I need to use this new "MATCH AGAINST" syntax in the sql string. http://dev.mysql.com/doc/refman/5.0/en/fulltext-search.html#function_match I think it would be really cool if, for certain columns only, I could override linq-to-nhibernate to change the sql it generates when I use .Where(x => FullTextIndexedStringProperty.Contains("Some word")).ToList(). Who can give me some general directions on how to get started? 回答1: This will get you a