NHibernate(无法定位类)
本文关键字:定位 NHibernate | 更新日期: 2023-09-27 18:21:49
我有下一个代码:
IUnitOfWork factory = DI.Get<IUnitOfWork>();
ISession session = (ISession)ReflectionUtils.GetPropertyValue(factory, "Session");
IQuery query = session.CreateQuery("SELECT new Model.TestClass(FechaCreacion,Demora) from Pedido");
TestClass[] _list = query.List<TestClass>().ToArray();
public class TestClass
{
public DateTime FechaCreacion { get; set; }
public int Demora { get; set; }
}
我需要返回一个对象列表,以便在数据网格视图中显示它们,但我得到了下一个异常:
NHibernate.QueryException was unhandled
Message=Unable to locate class [Model.TestClass] [SELECT new Model.TestClass(FechaCreacion,Demora) from Pedido]
Source=NHibernate
QueryString=SELECT new Model.TestClass(FechaCreacion,Demora) from Pedido
StackTrace:
en NHibernate.Hql.Ast.ANTLR.Tree.ConstructorNode.ResolveConstructor(String path) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Tree'ConstructorNode.cs:línea 151
en NHibernate.Hql.Ast.ANTLR.Tree.ConstructorNode.Prepare() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Tree'ConstructorNode.cs:línea 112
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.ProcessConstructor(IASTNode constructor) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'HqlSqlWalker.cs:línea 540
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectExpr() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 2761
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectExprList() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 2397
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectClause() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 2272
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.unionedQuery() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 1664
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.query() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 1510
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.selectStatement() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 536
en NHibernate.Hql.Ast.ANTLR.HqlSqlWalker.statement() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Generated'HqlSqlWalker.cs:línea 435
en NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'QueryTranslatorImpl.cs:línea 590
en NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'QueryTranslatorImpl.cs:línea 449
en NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'QueryTranslatorImpl.cs:línea 387
en NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'QueryTranslatorImpl.cs:línea 71
en NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'ASTQueryTranslatorFactory.cs:línea 43
en NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryString, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'ASTQueryTranslatorFactory.cs:línea 21
en NHibernate.Engine.Query.HQLStringQueryPlan.CreateTranslators(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Engine'Query'HQLStringQueryPlan.cs:línea 24
en NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Engine'Query'HQLStringQueryPlan.cs:línea 16
en NHibernate.Engine.Query.HQLStringQueryPlan..ctor(String hql, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Engine'Query'HQLStringQueryPlan.cs:línea 10
en NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(String queryString, Boolean shallow, IDictionary`2 enabledFilters) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Engine'Query'QueryPlanCache.cs:línea 61
en NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(String query, Boolean shallow) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Impl'AbstractSessionImpl.cs:línea 304
en NHibernate.Impl.AbstractSessionImpl.CreateQuery(String queryString) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Impl'AbstractSessionImpl.cs:línea 283
en Services.Services.Implementation.PedidoServiceImpl.ConsultaEsperaXCocinaYBarra() en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'Services'Services'Implementation'PedidoServiceImpl.cs:línea 124
en View.Frm_Consultas.btn_recuperar_Click(Object sender, EventArgs e) en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'View'Frm_Consultas.cs:línea 52
en System.Windows.Forms.Control.OnClick(EventArgs e)
en ComponentFactory.Krypton.Toolkit.KryptonButton.OnClick(EventArgs e)
en ComponentFactory.Krypton.Toolkit.KryptonButton.OnButtonClick(Object sender, MouseEventArgs e)
en ComponentFactory.Krypton.Toolkit.ButtonController.OnClick(MouseEventArgs e)
en ComponentFactory.Krypton.Toolkit.ButtonController.MouseUp(Control c, Point pt, MouseButtons button)
en ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
en ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
en ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
en ComponentFactory.Krypton.Toolkit.ViewBase.MouseUp(Point pt, MouseButtons button)
en ComponentFactory.Krypton.Toolkit.ViewManager.MouseUp(MouseEventArgs e, Point rawPt)
en ComponentFactory.Krypton.Toolkit.VisualControlBase.OnMouseUp(MouseEventArgs e)
en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
en System.Windows.Forms.Control.WndProc(Message& m)
en ComponentFactory.Krypton.Toolkit.VisualControlBase.WndProc(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
en System.Windows.Forms.Application.Run(Form mainForm)
en SPMontaPlatos.Program.<LoadApp>c__Binding.Invoke(Object& instance, Arguments arguments, Object aspectArgs) en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'SPMontaPlatos'Program.cs:línea 85
en PostSharp.Aspects.Internals.MethodInterceptionArgsImpl.Proceed()
en SPMontaPlatos.Aspects.Login.OnInvoke(MethodInterceptionArgs args) en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'SPMontaPlatos'Aspects'Login.cs:línea 30
en SPMontaPlatos.Program.LoadApp() en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'SPMontaPlatos'Program.cs:línea 83
en SPMontaPlatos.Program.Main() en C:'Repositorio'ProyectosCasinoClub'SPMontaPlatosOK'Code'SPMontaPlatos'Program.cs:línea 31
en System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
en System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
en Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
en System.Threading.ThreadHelper.ThreadStart_Context(Object state)
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
en System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
en System.Threading.ThreadHelper.ThreadStart()
InnerException: System.TypeLoadException
Message=Could not load type Model.TestClass. Possible cause: no assembly name specified.
Source=NHibernate
TypeName=""
StackTrace:
en NHibernate.Util.ReflectHelper.TypeFromAssembly(AssemblyQualifiedTypeName name, Boolean throwOnError) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Util'ReflectHelper.cs:línea 291
en NHibernate.Util.ReflectHelper.ClassForName(String name) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Util'ReflectHelper.cs:línea 181
en NHibernate.Hql.Ast.ANTLR.Tree.ConstructorNode.ResolveConstructor(String path) en d:'CSharp'NH'NH'nhibernate'src'NHibernate'Hql'Ast'ANTLR'Tree'ConstructorNode.cs:línea 146
InnerException:
如果有人能帮我,我将不胜感激,很抱歉我的英语很差。
您可以尝试在您的hbm文件中添加这样的内容:
<import class="NH.Domain.DTOs.ProductDTO, NH.Domain" />
以下是完整的解释:
http://gustavoringel.blogspot.com/2009/02/creating-dto-in-nhibernate-hql-using.html