我试图用这样的代码从我的表中只选择一些字段
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.List<Product>();
这段代码没有错误,但在运行时我得到了这个:“无法执行查找[SQL:SQL 不可用]”值“Prod1 不是 SympleFlhLINQ.Product 类型,并且不能用于这个泛型集合”。
如果有人告诉我如何只获取产品名称和引用的类别名称宽度,那将会非常好
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>();
或者
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>();
关于Nhibernate 查询结束,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11724054/