session queries the database, the identity map (1st level cache) only ensures a single instance of a object is referenced through the scope of the session. for this type of query you will need to persist the data, then query for it.
if you want to query transient objects then you need to use in memory filters (linq). BTW: you have a problem with your mappings. all your collections are not lazy. This will become a performance problem very quickly. On Oct 14, 1:20 pm, Trygve Lorentzen <[email protected]> wrote: > Unfortunately, the code I pasted in another post was not well > formatted (too much wrapping), but here goes... > > Hierarchy: > Raceday > <one-to-many> > Race > <one-to-many> > Result > <one-to-many>Horse > <one-to-many>Driver > > public class RacedayMap : ClassMap<Raceday> > { > public RacedayMap() > { > Id(x => x.RacedayID).Column("RacedayID"); > Map(x => x.RacedayNr); > Map(x => x.RDate); > Map(x => x.TrackCond); > Map(x => x.TrackValue); > Map(x => x.Weather); > > References(x => x.Track).Column("TrackID").Cascade.All(); > HasMany(x => x.Races) > .Cascade.All() > .Not.LazyLoad() > .Inverse() > .AsList() > .Access.CamelCaseField(Prefix.Underscore); > } > } > > public class RaceMap : ClassMap<Race> > { > public RaceMap() > { > Id(x => x.RaceID).Column("RaceID"); > Map(x => x.RaceNr); > Map(x => x.RaceType); > Map(x => x.StartMethod); > Map(x => x.HorseType); > > References(x => x.Raceday) > .Column("RacedayID") > .Cascade.All(); > HasMany(x => x.Results) > .Cascade > .AllDeleteOrphan() > .Not.LazyLoad() > .Inverse() > .AsList() > .Access.CamelCaseField(Prefix.Underscore); > } > } > public class ResultMap : ClassMap<Result> > { > public ResultMap() > { > Id(x => x.ResultID).Column("ResultID"); > Map(x => x.ResultNr); > Map(x => x.Startnr); > Map(x => x.Rail); > Map(x => x.Distance); > Map(x => x.Kmtime); > Map(x => x.Tottime); > Map(x => x.Price); > Map(x => x.Odds); > > References(x => x.Race).Column("RaceID").Cascade.All(); > References(x => > x.Horse).Column("HorseID").Cascade.SaveUpdate(); > References(x => > x.Driver).Column("DriverID").Cascade.SaveUpdate(); > } > } > > public class HorseMap : ClassMap<Horse> > { > public HorseMap() > { > Id(x => x.HorseID).Column("HorseID"); > Map(x => x.H_DB); > Map(x => x.HNameNor); > Map(x => x.YOB); > > References(x => > x.BirthCountry).Column("CountryCode").Cascade.SaveUpdate(); > } > } > > public class DriverMap : ClassMap<Driver> > { > public DriverMap() > { > Id(x => x.DriverID).Column("DriverID"); > Map(x => x.D_DB); > Map(x => x.DNameNor); > Map(x => x.DNameSwe); > Map(x => x.Amateur); > Map(x => x.License); > Map(x => x.Rikstoto_Driver_ID); > > References(x => > x.BirthCountry).Column("CountryCode").Cascade.SaveUpdate(); > } > } > > FAILING METHOD CALL (I want to search for a horse attached to session > either if it's persisted yet or not. My assumption was that the > session would first look in it's in-memory attached objects (without > persisting them first), then the DB if not found, but that assumption > is probably wrong?). > > result.Horse = HorseDao.GetHorseByHorseSearchData(hsd, session); > > public static Horse GetHorseByHorseSearchData(HorseSearchData > hsd, ISession session) > { > IList<Horse> horses = session.CreateCriteria<Horse>() > .Add(Restrictions.Eq("BirthCountry", > CountryDao.GetCountry_ByCountryCode(hsd.CountryCode))) > .Add(Restrictions.Eq("H_DB", hsd.Horsename_DBstring)) > .Add(Restrictions.Disjunction() > .Add(Restrictions.Eq("YOB", hsd.YOB)) > .Add(Restrictions.Eq("YOB", null)) > ) > .AddOrder(Order.Asc("HorseID")) > .List<Horse>(); > > if (horses.Count > 0) > return horses[0]; > > return new Horse(); > } > > On 14 Okt, 15:44, Jason Meckley <[email protected]> wrote: > > > a picture, code in this case, is worth 1K words :) provide the code > > with relevant mappings and we can help. > > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
