LINQ line problem
I am accessing my product types listed with Linq.
var types = (from t in NHibernateSession.Linq<Product>()
select t.ProductType).Distinct().ToList<ProductType>();
return types;
But providing it Cannot pass an error type object
'... Domain.Product' for type '... Domain.ProductType'.
ProductType is a property of Product.
<many-to-one name="ProductType" class="Portal.Domain.ProductType, TilePortal.Domain" column="ProductTypeID" not-null="true" ></many-to-one>
Edit: It looks like Linq for Nhibernate is not mature enough to handle such requests. I just want to be able to create a simple SQL query that fetches a single ProductType from the DB without bringing in all the products that don't go to the production db that has millions of products. So if you can illustrate how to do this using the HQL os Criteria API that will work as well.
a source to share
You may have a problem with the nHibernate LINQ implementation. You get the same error:
var types = (from t in NHibernateSession.Linq<Product>()
select t.Type);
If not, what happens when you try to use non-generic ToList()
?
var types = (from t in NHibernateSession.Linq<Product>()
select t.Type).Distinct().ToList();
As an aside, I've generally avoided creating a class with a name that conflicts with something in the .NET framework, especially something as basic as Type. This can only lead to confusion. Perhaps you should rename ProductType.
a source to share
I'm pretty sure the linq 2 nh implementation doesn't support this kind of thing yet. You will probably have to execute sql first and then select the type reference. Like this:
var types = (from t in NHibernateSession.Linq<Product>()
select t).ToList().Select(t => t.Type).Distinct().ToList<Type>();
return types;
If you are not using the latest version of the provider, please update it and try again. If implemented, it should work fine.
Update
If the only thing you want to do is get all types of products. Why not just write this simple query?
var types = (from t in NHibernateSession.Linq<ProductType>()
select t).ToList();
No need to ask for your products when you need types.
a source to share