34 lines
765 B
C#
34 lines
765 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>(string propertyName, object val) where T : BeWoEntityBase, new()
|
|
{
|
|
var criteria = CreateCriteria<T>()
|
|
.Add(Restrictions.Eq(propertyName, val));
|
|
|
|
var candidates = criteria.List<T>();
|
|
|
|
if(candidates.Count == 1)
|
|
return candidates[0];
|
|
|
|
if (candidates.Count == 0)
|
|
return null;
|
|
// throw new NotImplementedException("Count == 0");
|
|
|
|
throw new NotImplementedException("Count > 1");
|
|
}
|
|
}
|
|
}
|