using BeWo.Data.Entities; using BS.Shared; using NHibernate.Criterion; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BeWo.Data.Access { public class GenericSearchDAO : AbstractBaseDAO { internal GenericSearchDAO() { } public virtual T LoadEntityByProperty(string propertyName, object val) where T : BeWoEntityBase, new() { var criteria = CreateCriteria() .Add(Restrictions.Eq(propertyName, val)); var candidates = criteria.List(); if(candidates.Count == 1) return candidates[0]; if (candidates.Count == 0) return null; // throw new NotImplementedException("Count == 0"); throw new NotImplementedException("Count > 1"); } } }