Files
BeWoPlaner/Data/Access/GenericSearchDAO.cs

36 lines
850 B
C#

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