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(Func propertyFunc, string propertyName = null) where T : BeWoEntityBase, new() { if (propertyName is null) propertyName = nameof(propertyFunc); var criteria = CreateCriteria() .Add(Restrictions.Eq(propertyName, propertyFunc)); var candidates = criteria.List(); if(candidates.Count == 1) return candidates[0]; if (candidates.Count == 0) throw new NotImplementedException("Count == 0"); throw new NotImplementedException("Count > 1"); } } }