问题描述
我想加盟别名多次,但是这取决于它应该做的次数。
员工employeeAlias = NULL;
事情thingAlias = NULL;
变种名称=字符串[] {A,B,C,D,E} //值的数量可以改变
的for(int i = 0;我< names.Length;我++)
{
queryOver
.JoinAlias(()=> employeeAlias.Things,
()=> thingAlias,
JoinType .LeftOuterJoin,
Restrictions.Eq(Projections.Property(()=> thingAlias.Name,
名称由[i]));
}
然而,在执行时,NHibernate的抛出一个错误说:
NHibernate.QueryException:重复别名:thingAlias ---> System.ArgumentException:具有相同键的项已被添加
有没有一种办法可以让NHibernate的加入一个别名与指定的名称,这样就不会再使用该变量的名字吗?
谢谢你们。这一直是。从昨天开始我的问题,我无法找到一个妥善的解决办法。
PS:
我想做这样的事情:
SELECT * FROM员工Ë
LEFT OUTER JOIN事情T于e.Id = T .EmployeedId和t.Name =A
LEFT OUTER JOIN事情T于e.Id = t.EmployeedId AND t.Name =b
你正在尝试实现是不可能的。每个关系(多到一
,一对许多
)可只能使用一次。
要支持这个说法,请点击此处查看:的
私人无效CreateAssociationPathCriteriaMap()
{
的foreach(CriteriaImpl.Subcriteria暴击rootCriteria.IterateSubcriteria())
{
串wholeAssociationPath = GetWholeAssociationPath(暴击);
试
{
associationPathCriteriaMap.Add(wholeAssociationPath,暴击);
}
赶上(ArgumentException的AE)
{
抛出新QueryException(重复协会路径:
+ wholeAssociationPath,AE);
}
所以,我们可以在这里看到,无论别名,到了最后,所有associtated关系(连接)加入到 associationPathCriteriaMap
,这是的IDictionary<字符串的ICriteria>
。
这意味着,现在有办法了如何在比赛中两个相同的键...
I am trying to join aliases multiple times but it depends on the number of times it should do it.
Employee employeeAlias = null;
Thing thingAlias = null;
var names = string[] {"A", "B", "C", "D", "E"} // number of values could vary
for(int i = 0; i < names.Length ; i++)
{
queryOver
.JoinAlias(() => employeeAlias.Things,
() => thingAlias,
JoinType.LeftOuterJoin,
Restrictions.Eq(Projections.Property(() => thingAlias.Name,
names[i]));
}
However, upon execution, NHibernate throws an error saying:
NHibernate.QueryException: duplicate alias: thingAlias ---> System.ArgumentException: An item with the same key has already been added
Is there a way I can make NHibernate join an alias with a specified name so that it will not re-use the name of the variable?
Thanks guys. This has been my problem since yesterday and I can't find a proper solution.
PS:
I'm trying to do something like this:
SELECT * FROM Employee e
LEFT OUTER JOIN Thing t on e.Id = t.EmployeedId AND t.Name = "A"
LEFT OUTER JOIN Thing t on e.Id = t.EmployeedId AND t.Name = "B"
What you are trying to achieve is impossible. Each relation (many-to-one
, one-to-many
) can be used exactly once.
To support this statement, please, check it here: CriteriaQueryTranslator.cs
private void CreateAssociationPathCriteriaMap()
{
foreach (CriteriaImpl.Subcriteria crit in rootCriteria.IterateSubcriteria())
{
string wholeAssociationPath = GetWholeAssociationPath(crit);
try
{
associationPathCriteriaMap.Add(wholeAssociationPath, crit);
}
catch (ArgumentException ae)
{
throw new QueryException("duplicate association path: "
+ wholeAssociationPath, ae);
}
So, what we can see here, regardless of aliases, at the end, all associtated relations (JOINS) are added into associationPathCriteriaMap
, which is IDictionary<string, ICriteria>
.
That means, that there is now way how to have two same keys in play...
这篇关于重命名NHibernate的标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!