Note that there are some explanatory texts on larger screens.

plurals
  1. POLINQ to NHibernate: could not resolve property
    primarykey
    data
    text
    <p>Fluent nHibernate using nHibernate v. 2.1.2.4, nHibernate.Linq v. 1.1.0.1001, and Fluent NHibernate v. 1.1.0.685.</p> <p>I have a domain object with a DateTime field called DateOfEvent. This is an actual date/time field in the database. I've also added 2 new properties YearOfEvent which grabs the Year from the DateOfEvent field as well as MontOfEvent which grabs the Month from the DateOfEvent field.</p> <pre><code>public class Event { public Event() { } public virtual Int32 Id { get; set; } public virtual String Title { get; set; } public virtual DateTime DateOfEvent { get; set; } public virtual Int32 YearOfEvent { get { return DateOfEvent.Year; } } public virtual Int32 MonthOfEvent { get { return DateOfEvent.Month; } } public virtual String Location { get; set; } public virtual String City { get; set; } public virtual String State { get; set; } public virtual String Zip { get; set; } public virtual String Description { get; set; } public virtual Boolean HasImage { get; set; } public virtual Boolean IsActive { get; set; } } </code></pre> <p>However, when running this method:</p> <pre><code>public IList&lt;Event&gt; GetActiveEvents(int pageNumber, int pageSize, out int totalItems) { Int32 skip = Misc.NumberToSkip(pageNumber, pageSize); totalItems = (from e in _session.Linq&lt;Event&gt;() where e.IsActive select e).Count(); return (from e in _session.Linq&lt;Event&gt;() where e.IsActive select e) .Skip(skip) .Take(pageSize) .ToList(); } </code></pre> <p>NHibernate.QueryException: could not resolve property: YearOfEvent of: ....Event</p> <p>FWIW, I've blurred out the name of the project. ;)</p> <p>Any idea how to get this query working?</p> <p>Thanks! -Steve</p> <p>EDIT: Here's my mapping class:</p> <pre><code>public class EventMap : ClassMap&lt;Event&gt; { public EventMap() { Table("tbl_event"); Id(x =&gt; x.Id, "eventId"); Map(x =&gt; x.DateOfEvent, "dateOfEvent"); Map(x =&gt; x.Description, "description"); Map(x =&gt; x.Title, "title"); Map(x =&gt; x.Location, "location"); Map(x =&gt; x.State, "state"); Map(x =&gt; x.City, "city"); Map(x =&gt; x.Zip, "zip"); Map(x =&gt; x.HasImage, "hasImage"); Map(x =&gt; x.IsActive, "isActive"); } } </code></pre> <p>...and my config:</p> <pre><code>public Configuration GetConfiguration() { Configuration configuration; var assembly = Assembly.Load(".....Data"); var fluentConfig = Fluently.Configure() .Database(MySQLConfiguration.Standard.ConnectionString( c =&gt; c.FromConnectionStringWithKey("......") )) .Mappings(m =&gt; m.FluentMappings.AddFromAssembly(assembly)); configuration = fluentConfig.BuildConfiguration(); configuration.Properties.Add("hbm2ddl.keywords", "none"); return configuration; } </code></pre> <p>I also just tried the Criteria API:</p> <pre><code>return _session.CreateCriteria(typeof (Event)) .Add(Expression.Eq("IsActive", true)) .Add(Expression.Eq("YearOfEvent", year)) .List&lt;Event&gt;(); </code></pre> <p>No workie either.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload