Im trying to select only some fields from my table with code like this
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.List<Product>();
No errors with this code but in runtime i got this: "Unable to perform find[SQL: SQL not available]" the value "Prod1 is not of type SympleFlhLINQ.Product and and cannot be used on this generic collection".
And will be very nice if someone tell me how i can fetch only product name and referenced category name width something like this
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.Select(x=>x.Cat.CategoryName)
.List<Product>();
IList<string> names = sess.QueryOver<Product>()
.Select(x =>x.Name)
.List<string>();
or
ProductDto product = null;
Category category = null;
IList<ProductDto> res = sess.QueryOver<Product>()
.JoinAlias(x => x.Category, () => category)
.SelectList(list => list
.Select(x => x.Name).WithAlias(() => product.Name)
.Select(() => category.Name).WithAlias(() => product.CategoryName))
.TransformUsing(Transformers.AliasToBean<ProductDto>())
.List<ProductDto>();
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