2025-09-23 10:39:50 +02:00
|
|
|
|
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() { }
|
|
|
|
|
|
|
2026-03-25 11:38:24 +01:00
|
|
|
|
public virtual T LoadEntityByProperty<T>(string propertyName, object val) where T : BeWoEntityBase, new()
|
2025-09-23 10:39:50 +02:00
|
|
|
|
{
|
|
|
|
|
|
var criteria = CreateCriteria<T>()
|
2026-03-25 11:38:24 +01:00
|
|
|
|
.Add(Restrictions.Eq(propertyName, val));
|
2025-09-23 10:39:50 +02:00
|
|
|
|
|
|
|
|
|
|
var candidates = criteria.List<T>();
|
|
|
|
|
|
|
|
|
|
|
|
if(candidates.Count == 1)
|
|
|
|
|
|
return candidates[0];
|
|
|
|
|
|
|
|
|
|
|
|
if (candidates.Count == 0)
|
2026-03-25 11:38:24 +01:00
|
|
|
|
return null;
|
|
|
|
|
|
// throw new NotImplementedException("Count == 0");
|
2025-09-23 10:39:50 +02:00
|
|
|
|
|
|
|
|
|
|
throw new NotImplementedException("Count > 1");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|