I have the following simple function:
public class BaseEntityRepository<TEntity, TId> : IBaseEntityRepository<TEntity, TId>
where TEntity : class, TBaseEntity, IIdentifiedEntity<TId>
where TId : struct {
//...
public virtual TEntity GetById(TId id) {
return (from e in GetAll() where e.Id.Equals(id) select e).SingleOrDefault();
}
//...
}
Since TId is a generic I'm receiving the following message:
"Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."
No matter what type it represent. I've tried "Byte", "Int16", "Int32", "Long"... The message is the same. I thought that defining the generic constraint as struct would be enought to the type be reconized as a primitive.
BTW... GetAll() returns an IQueryable<TEntity>
.
Anyway... Does anybody know an workaround? Thanks
How about IEquatable?
where TId : IEquatable<TId>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With