You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel.SQL/DDD/IdentitySpecification.cs

51 lines
1.4 KiB

using System;
using System.Runtime.Serialization;
using ZeroLevel.Specification;
namespace ZeroLevel.SqlServer
{
[DataContract]
[Serializable]
public class IdentitySpecification<T> : BaseSpecification<T>
where T : IEntity
{
[DataMember]
protected Guid _id;
public IdentitySpecification(Guid id)
{
_id = id;
}
public override bool IsSatisfiedBy(T o)
{
return o.Id == _id;
}
public static ISpecification<T> Create(Guid id) { return new IdentitySpecification<T>(id); }
public static ISpecification<T> Create(IEntity entity) { return new IdentitySpecification<T>(entity.Id); }
}
[DataContract]
[Serializable]
public class IdentitySpecification<T, TKey> : BaseSpecification<T>
{
[DataMember]
private TKey _id;
private readonly IDbMapper<T> _mapper;
5 years ago
public IdentitySpecification(TKey id, bool mapOnlyMarkedMembers)
{
_id = id;
5 years ago
_mapper = DbMapperFactory.Create<T>(mapOnlyMarkedMembers);
}
public override bool IsSatisfiedBy(T o)
{
return _mapper.Id(o).Equals(_id);
}
5 years ago
public static ISpecification<T> Create(TKey id, bool mapOnlyMarkedMembers) { return new IdentitySpecification<T, TKey>(id, mapOnlyMarkedMembers); }
}
}

Powered by TurnKey Linux.