【发布时间】:2014-07-25 05:02:39
【问题描述】:
我正在尝试实现一个连接查询。我需要获取列 id 的名称
string hql = "select new TerminalStateReportItem(p.Ip, p.Error, p.Terminal_Id, p.Last_Activity, p.Current_Page, p.Ping, u.Name) from TerminalState p join User u on p.Terminal_Id=u.Id";
var query = new SimpleQuery<TerminalStateReportItem>(hql);
return query.Execute();
我收到一个错误
Castle.ActiveRecord.Framework.ActiveRecordException: 无法为 TerminalStateReportItem 执行 ExecuteQuery ---> NHibernate.Hql.Ast.ANTLR.SemanticException: 路径需要加入! [select new TerminalStateReportItem(p.Ip, p.Error, p.Terminal_Id, p.Last_Activity, p.Current_Page, p.Ping, u.Name) from KioskServer.TerminalState.TerminalState p join User1 u on p.Terminal_Id=u。编号]
我的类包装器
namespace KioskServer.Reports
{
[ActiveRecord]
public class TerminalStateReportItem
{
public TerminalStateReportItem()
{
}
public TerminalStateReportItem(string ip, string error, int terminalId, DateTime lastActivity, string currentPage, int ping, string name)
{
Ip = ip;
Error = error;
Terminal_Id = terminalId;
Last_Activity = lastActivity;
Current_Page = currentPage;
Ping = ping;
Name = name;
}
[PrimaryKey]
public string Ip { get; set; }
public string Error { get; set; }
public int Terminal_Id { get; set; }
public DateTime Last_Activity { get; set; }
public string Current_Page { get; set; }
public int Ping { get; set; }
public string Name{ get; set; }
}
}
我的班级表
namespace KioskServer.TerminalState
{
[ActiveRecord("terminal_state")]
public class TerminalState
{
public TerminalState(){
}
public TerminalState(string ip, string error, int terminalId, DateTime lastActivity, string currentPage, int ping)
{
Ip = ip;
Error = error;
Terminal_Id = terminalId;
Last_Activity = lastActivity;
Current_Page = currentPage;
Ping = ping;
}
[PrimaryKey]
public string Ip { get; set; }
[Property]
public string Error { get; set; }
[Property]
public int Terminal_Id { get; set; }
[Property]
public DateTime Last_Activity { get; set; }
[Property]
public string Current_Page { get; set; }
[Property]
public int Ping { get; set; }
}
}
不加入所有作品都正常。可能是因为我的课程在不同的文件夹中?
namespace KioskServer.Data.Users
{
[ActiveRecord("users",
DiscriminatorColumn = "usertype",
DiscriminatorType = "string",
DiscriminatorValue = "user")]
public class User : Entity
{
[Property]
public string Name { get; set; }
[Property]
public string Login { get; set; }
[Property]
public string Password { get; set; }
[Property]
public DateTime Date { get; set; }
[BelongsTo]
public Dealer Dealer { get; set; }
}
}
我做一个查询
string hql = "select new TerminalStateItem(p.Ip, p.Error, p.Terminal_Id, p.Last_Activity, p.Current_Page, p.Ping, u.Name) from TerminalState p join p.User u";
错误
NHibernate.QueryException: could not resolve property: User of: KioskServer.TerminalState.TerminalState [select new TerminalStateItem(p.Ip, p.Error, p.Terminal_Id, p.Last_Activity, p.Current_Page, p.Ping, u.Name) from KioskServer.TerminalState.TerminalState p join p.User u]
【问题讨论】:
标签: c# nhibernate join