Fluent nHibernate using nHibernate v. 2.1.2.4, nHibernate.Linq v. 1.1.0.1001, and Fluent NHibernate v. 1.1.0.685.
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.
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; }
}
However, when running this method:
public IList<Event> GetActiveEvents(int pageNumber, int pageSize, out int totalItems)
{
Int32 skip = Misc.NumberToSkip(pageNumber, pageSize);
totalItems = (from e in _session.Linq<Event>()
where e.IsActive
select e).Count();
return (from e in _session.Linq<Event>()
where e.IsActive
select e)
.Skip(skip)
.Take(pageSize)
.ToList();
}
NHibernate.QueryException: could not resolve property: YearOfEvent of: ....Event
FWIW, I've blurred out the name of the project. ;)
Any idea how to get this query working?
Thanks! -Steve
EDIT: Here's my mapping class:
public class EventMap : ClassMap<Event>
{
public EventMap()
{
Table("tbl_event");
Id(x => x.Id, "eventId");
Map(x => x.DateOfEvent, "dateOfEvent");
Map(x => x.Description, "description");
Map(x => x.Title, "title");
Map(x => x.Location, "location");
Map(x => x.State, "state");
Map(x => x.City, "city");
Map(x => x.Zip, "zip");
Map(x => x.HasImage, "hasImage");
Map(x => x.IsActive, "isActive");
}
}
...and my config:
public Configuration GetConfiguration()
{
Configuration configuration;
var assembly = Assembly.Load(".....Data");
var fluentConfig = Fluently.Configure()
.Database(MySQLConfiguration.Standard.ConnectionString(
c => c.FromConnectionStringWithKey("......")
))
.Mappings(m => m.FluentMappings.AddFromAssembly(assembly));
configuration = fluentConfig.BuildConfiguration();
configuration.Properties.Add("hbm2ddl.keywords", "none");
return configuration;
}
I also just tried the Criteria API:
return _session.CreateCriteria(typeof (Event))
.Add(Expression.Eq("IsActive", true))
.Add(Expression.Eq("YearOfEvent", year))
.List<Event>();
No workie either.