max*_*s87 4 nhibernate queryover
我试图只用这样的代码从我的表中选择一些字段
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.List<Product>();
Run Code Online (Sandbox Code Playgroud)
没有这个代码的错误,但在运行时我得到了这个:"无法执行查找[SQL:SQL不可用]"值"Prod1不是SympleFlhLINQ.Product类型,并且不能在此通用集合上使用".
如果有人告诉我如何只获取产品名称和引用的类别名称宽度,这将是非常好的
IList<Product> res = sess.QueryOver<Product>()
.Select(x =>x.name)
.Select(x=>x.Cat.CategoryName)
.List<Product>();
Run Code Online (Sandbox Code Playgroud)
IList<string> names = sess.QueryOver<Product>()
.Select(x =>x.Name)
.List<string>();
Run Code Online (Sandbox Code Playgroud)
要么
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>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3569 次 |
| 最近记录: |