C# – WCF OperationContract and Nhibernate ICriteria

apicdata-access-layernhibernatewcf

We are trying to create a cool API using WCF and ICriteria, for example:

[ServiceContract]
public class ProductService
{
[OperationContract]
public List<Product> Get()

[OperationContract]
public List<Product> GetByCriteria(Criteria criteria)

}

We are thinking of using the DetachedCriteria so anyone can send it and we connect this to the Session in the Service for running the Query infront of our DB.

Is there anyone who create such API?
Should we use the ICriteria from Nhibernate?
Any other cool Ideas?

Thanks.

Best Answer

This is not cool API. It's object oriented, not service oriented. And it will not work.

You will have to use KnownTypeAttribute (or ServiceKnownTypeAttribute) for polymorphic queries. (see this question).

Also this is not very elegant solution and I would discourage you from that. Be explicit when in Service World.