linq-to-nhibernate

NHibernate.QueryException: could not resolve property

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 01:49:09
问题 I'm using FluentNHibernate and Linq To Nhibernate, with these entities (only the relevant parts): public class Player : BaseEntity<Player> { private readonly IList<PlayerInTeam> allTeams = new List<PlayerInTeam>(); public IEnumerable<Team> Teams { get { return from playerInTeam in allTeams where playerInTeam.Roster.Match == null select playerInTeam.Roster.Team; } } } public class PlayerInTeam : BaseEntity<PlayerInTeam> { public int PlayerNumber { get; set; } public Player Player { get; set; }

LINQ to NHibernate WHERE EXISTS IN

半世苍凉 提交于 2019-12-10 22:27:13
问题 I've been trying out NHibernate 3 and LINQ to NHibernate. I can't get it to spit out the correct T-SQL query. Here's my domain model: Employee { id, name } Department { id, name } EmployeeDepartment { id, employee_id, department_id, startdate, enddate } AttendanceRegistration { id, datetime, employee_id } Now suppose I'd like to select all AttendanceRegistrations between '2010-10-1' and '2010-11-1' that were connected to a certain department at that time. DateTime start = new DateTime(2010,10

Map One to One Relationship at Run-Time

£可爱£侵袭症+ 提交于 2019-12-10 21:31:13
问题 i'm trying to upgrade an old CMS to use NHibernate and can't deter from the original database structure much. Here is the bit which is causing an issue. Say i have the following 2 tables: Articles: - Id (PK, Identity) - Title - Content Meta: - ArticleId (PK, FK to Articles) - Description - Keywords I have created the following classes: public class Article { public virtual int Id { get; set; } public virtual string Title { get; set; } public virtual string Content { get; set; } } public class

Setting Linq to NHibernate ADO Command Timeout

一个人想着一个人 提交于 2019-12-10 18:54:54
问题 How do I increase the timeout in NHibernate Linq To Sql? Not the Connection Timeout but the ado command timeout. using (ISession session = NHibernateHelper.OpenSession(NHibernateHelper.Databases.CarrierCDR)) using (session.BeginTransaction(IsolationLevel.ReadUncommitted)) { lCdrs = (from verizon in session.Linq<Domain.Verizon>() where verizon.Research == true && verizon.ReferenceTable == null orderby verizon.CallBillingDate descending select verizon).ToList(); } 回答1: if you are configuring

NHibernate 3 - extending Linq provider BaseHqlGeneratorForMethod.BuildHql problem

淺唱寂寞╮ 提交于 2019-12-10 17:34:39
问题 I want to extend the default LINQ provider for NHibernate 3 with methods of my own. I want to be able to use some methods from my POCOs. I have a component named Range which is used quite often in many of my POCOs. This nhibernate component class has a method Contains(int value) that I want to use in LINQ query expressions Mapping: <class name="Foo"> ... <component name="AgeRange"> <property name="Min" column="age_min" /> <property name="Max" column="age_max" /> </component> </class> Class

Linq to nhibernate - Where collection contains object with id

偶尔善良 提交于 2019-12-10 16:38:57
问题 I have 2 objects like this public class Child { public virtual int ChildId { get; set; } } public class Parent { public virtual int ParentId { get; set; } public virtual IList<Child> Children { get; set; } } I am trying to write a linq to nhibernate query to select a parent where it contains a child with a specific id. return x => x.Children.Contains does not work. I also tried this. return x => (from y in x.Children where y.ChildId.Equals(childId) select y).Count() > 0 My fluent mapping

Why ordinary laws in evaluating boolean expression does not fit into LINQ?

拟墨画扇 提交于 2019-12-10 09:31:14
问题 In such a code: if (insuranceNumberSearch == null ? true : ei.InsuranceNumber.Contains(insuranceNumberSearch.Trim())) doSomething(); where insuranceNumberSearch is null, remaining expression is not null while in following code: var q = from ei in session.Linq<EmployeeInsurance>() where insuranceNumberSearch == null ? true : ei.InsuranceNumber.Contains(insuranceNumberSearch.Trim()) select ei; all section of expression is evaluated regardless of insuranceNumberSearch is null or is not null. I'm

Can NHibernate query for specific children without lazy loading the entire collection?

六月ゝ 毕业季﹏ 提交于 2019-12-09 21:15:05
问题 When I have an entity object with a one-to-many child collection, and I need to query for a specific child object, is there a feature or some clever pattern I haven't come up with yet to avoid that NHibernate fetches the entire child collection? Example: class Parent { public virtual int Id { get; proteced set; } // generated PK public virtual IEnumerable<Child> Children { get; proteced set; } } class Child { public virtual int Id { get; protected set; } // generated PK public virtual string

Nhibernate .Fetch calls fail on a mocked session

試著忘記壹切 提交于 2019-12-09 17:05:06
问题 I love NHibernate (and NHibernate.Linq). I don't prematurely optimize, but sometimes I'll hit a really nasty N+1 issue. The recommended fix for the N+1 is to use NH's Fetch extension method. The problem arises when I create a Mock of the ISession . I'll create a List<User> and set my mock to return the list whenever someone calls _session.Query<User>() . When I add a Fetch call to the query (i.e. _session.Query<User>().Fetch(u => u.Address) , I get the following error message: There is no

NHibernate (3.1.0.4000) NullReferenceException using Query<> and NHibernate Facility

我怕爱的太早我们不能终老 提交于 2019-12-09 16:25:55
问题 I have a problem with NHibernate, I can't seem to find any solution for. In my project I have a simple entity (Batch), but whenever I try and run the following test, I get an exception. I've triede a couple of different ways to perform a similar query, but almost identical exception for all (it differs in which LINQ method being executed). The first test: [Test] public void QueryLatestBatch() { using (var session = SessionManager.OpenSession()) { var batch = session.Query<Batch>()