NHibernate查询问题..在线等答案...

qq249529304 2009-06-29 12:50:30
string sql = "select * from(select s.ID as ID,s.Name as Name,s.PictureUrl as PictureUrl,q.Price as Price,a.Name as BigTypeName from Software as s,Quotation as q,Agent as a where q.Agent_ID = a.ID and q.Software_ID =s.ID) as Software";

return _session.CreateSQLQuery(sql).AddEntity("software", typeof(Software)).List<Software>();

我想把上面的SQL语句执行然后放在IList<Software>中。不知道怎么实现
***********下面是实体类的属性定义**********************
public class Software
{
#region NHFrog自维护属性,请不要使用代码编程器

// 主键的私有变量
private int mID;

// 名称的私有变量
private string mName;

// 对应的官网产品SoftID的私有变量
private string mSoftID;

// 所属分类的私有变量
private SoftCategory mSoftCategory;

// 对应速达官网上的大类名称的私有变量
private string mBigTypeName;

// 单位的私有变量
private string mPriceUnit;

// 市场价格的私有变量
private decimal mPrice;

// 图片地址的私有变量
private string mPictureUrl;
......

************************************************
...全文
55 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不知道你执行Sql语句后返回的是什么


List l = new ArrayList();
//
for(int i=0;i<;i++){
Software s = new Software();
s.mID=;
m.mName=;
l.add(s);
}
return l;
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
返回一个集合。集合由object[]集合构成。例如:ret.count =2 ,ret[0] =Object{1,qq,21,lan} ...
我要怎么样把它放拆箱到实体集合里去。
sunshine_anycall 2009-06-29
  • 打赏
  • 举报
回复
报什么错,发出来,要不怎么看
光靠猜啊
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
上面的哥哥,你抄起我的也没用啦,会报错的啦。。要不然,我不得拿来问了。。
sunshine_anycall 2009-06-29
  • 打赏
  • 举报
回复


public IList<Software> GetAll()
{
string sql = "select * from(select s.ID as ID,s.Name as Name,s.PictureUrl as PictureUrl,q.Price as Price,a.Name as BigTypeName from Software as s,Quotation as q,Agent as a where q.Agent_ID = a.ID and q.Software_ID =s.ID) as Software";

return _session.CreateSQLQuery(sql).AddEntity("software", typeof(Software)).List <Software>();
}
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
qiujiu a....
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
实体没错..我主要是要知道怎么处理查询,然后返回值存为IList<Software>
sunshine_anycall 2009-06-29
  • 打赏
  • 举报
回复

//VS2008
//实体类定义属性修饰符为public virtual
//配置文件
public class Software
{
#region NHFrog自维护属性,请不要使用代码编程器

// 主键的私有变量
public virtual int ID
{get;set;}

// 名称的私有变量
public virtual string Name
{get;set;}
sunshine_anycall 2009-06-29
  • 打赏
  • 举报
回复
实体类定义错误
//属性必须是virtual修饰
public class Software
{
#region NHFrog自维护属性,请不要使用代码编程器

// 主键的私有变量
private virtual int mID;

// 名称的私有变量
private virtual string mName;
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
各位大哥大姐。帮帮忙啦。。
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
谁能给我个好的解决方案呀。。
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jijunwu 的回复:]

C# code
List<Software> l = (Software)_session.CreateSQLQuery(sql).AddEntity("software", typeof(Software)).List <Software>();
[/Quote]

这样强制转换也行吗?试试先。应该不行的。后面就设置了返回实体类型了。AddEntity("software", typeof(Software))
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 qq249529304 的回复:]
我也不知道,返回的是什么格式的,是Object类型的。
[/Quote]

List<Software> l = (Software)_session.CreateSQLQuery(sql).AddEntity("software", typeof(Software)).List <Software>();

qq249529304 2009-06-29
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 gongsun 的回复:]
C# code
// 获取结果
IList results = query.List();

// 转化结果为Array
Software[] soft = new UserTalk[results.Count];

results.CopyTo(soft, 0);
[/Quote]

这样行吗?我试试先。但是,感觉不太懂。为什么不用IList<Software>
gongsun 2009-06-29
  • 打赏
  • 举报
回复

// 获取结果
IList results = query.List();

// 转化结果为Array
Software[] soft = new UserTalk[results.Count];

results.CopyTo(soft, 0);
qq249529304 2009-06-29
  • 打赏
  • 举报
回复
我也不知道,返回的是什么格式的,是Object类型的。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧