- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我们有一个名为 Customer 的表,它具有三个子类/表,即。 Cust1、Cust2 和 Cust3 由 hbm 使用连接子类链接。
所有 4 个表都以 CustomerId 作为主键。客户表中的一条记录将在 Cust1 或 Cust 2 或 Cust3 表中有一条记录。
使用标准 Nhibernate List() 获取列表可以正确获取类及其子类。
但是,为了优化我们的查询,我们不得不使用 CreateSQlQuery 方法。
在goolging上,我们发现获取类及其子类的正确方法是有一个选择查询,例如
var sqlQuery = Session.CreateSqlQuery(
select C.*,
case if C1.CustId is not null then 1
else if C2.CustId is not null then 2
....
from Customer C
left join Cust1 C1 on C1.CustId = C1.CustId
left join Cust2 C2 on C2.CustId
where C.CustID in (x,y,z,blah,blah).).
sqlQuery.AdddEntity("C",typeof(Customer));
sqlQuery.List();
当 Nhibernate 在内部生成查询时,需要更改 case 和 alais 以区分 4 个表之间的 CUstId 列,否则会抛出 clazz 错误..
在运行查询时,我们得到 Nhibernate 异常为
"IndexOutOfRangeException - Duration"
Cust1(子类)表有一个名为 Duration 的列。我将表列重命名为 Duration_BE 以检查列名是否是问题,,然后它抛出了错误
"IndexOutOfRangeException - Duration-BE"
这种工作模式的引用是.. http://www.methodicmadness.com/2009/01/nhibernate-what-is-heck-clazz.html
谁能帮帮我。
最佳答案
确保您选择了所有表格中的所有字段。
例如
var sqlQuery = Session.CreateSqlQuery(@"
select
C.*,
C1.*,
C2.*, -- You need all of the fields from the joined tables
case
if C1.CustId is not null then 1
else if C2.CustId is not null then 2
end as clazz_
from
Customer C
left join Cust1 C1 on C.CustId = C1.CustId
left join Cust2 C2 on C.CustId = C2.CustId
where
C.CustID in (x,y,z)"
);
关于c# - Nhibernate - 创建 SQLQuery - IndexOutOfRangeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2220775/
我想在文本框中显示数据库中的某些列。运行代码时,@ApplicantUsername出现错误 IndexOutOfRangeException 这是我的代码: cs.Open();
我基本上需要将任意数量的内容数组存储为一个整数,但之后我必须将其全部回显。 我收到索引超出范围错误。 for (int index = 0; index 0; index--, userArray-
当我尝试访问特定数组索引时,我正在寻找一种方法来防止 IndexOutOfRangeException。 我有一个通用代码,有时在 array[index] 中有值,有时则没有。 所以,在尝试获取它的
我不知道为什么:float val = spectrum[i];正在产生超出数组范围的索引。请帮忙...!我是这个游戏的新手。 public class InputScript : MonoBehav
我正在编写一个 Unity 脚本来读取 CSV 文件(二维和所有数字),将其分解为附加到二维 float 组的 float 。这是我的代码: using System.Collections; usi
这个问题在这里已经有了答案: What does IndexOutofRangeException mean? (3 个答案) 关闭 9 年前。 string Query = "SELECT [AA
我不明白为什么我会在下面的代码中遇到超出范围的异常。 _maxRowIndex 和 _maxColIndex 的值分别为 5 和 0。当 row 和 col 都等于 0 时,第一次抛出异常。我不明白为
程序在运行时说索引超出范围,但我不知道为什么。 错误信息指出的行是 点[计数器 + ((int)(radius * 100))].X = i; 如果那个有错误,下一个(具有相同索引)也一定有错误。 P
这个问题在这里已经有了答案: C# Creating an array of arrays (5 个答案) 关闭 7 年前。 我遇到了这个奇怪的 IndexOutOfRangeException 异
我正在制作一个简单的购物车。它从另一个页面上的按钮将产品添加到购物车页面,我的添加到购物车按钮如下所示 protected void addCart_Click(object sender, Eve
我不明白为什么我在下面的 Where 子句中得到它。 using System; using System.Linq; public static class Extensions { ///
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我有一个问题。我尝试实现 Zig-Zag 算法 ( Rail Fence )。 我的代码如下所示: int n = 3; int j = 0; int charCounter
在 Form1 构造函数中我有: if (System.IO.File.Exists(keywords_path_file)) { ListBo
我在一些任务中使用字典。 从逻辑上讲,我已将其设置为我的键永远不会发生冲突,但有时在我向字典添加内容时会出现此异常。 Index was outside the bounds of the array
我们目前在我们的一个应用程序中使用 SpreadsheetGear 来生成 Excel 工作簿。我试图在 ASP.NET Web 应用程序中重用其中的一些功能,但到目前为止我很难过。 我首先在 Web
我有以下映射: public class SecurityMap : ClassMap { public SecurityMap() {
我有一个非常简单的类,给出了一个奇怪的错误。该类只有1个属性,查询非常简单。最可怕的是,这似乎是随机发生的。收到此错误后,通常刷新页面可以使其变路,并且应用程序不会再出现此错误。 数据库连接可能有问题
我又遇到了另一个问题。我试图使用 DataReader 从数据库中获取数据,但在测试代码时出现错误。谁能帮我吗?错误发生在这一行: chkAssess = readAssess[columnName]
我还有另外两个按钮,代码几乎完全相同。但是,当我尝试运行此代码以获取所有结果时,出现错误“System.IndexOutOfRangeException”。 显示无效 NHS 号码按钮有效,但我不明白
我是一名优秀的程序员,十分优秀!