如果你知道,当你打电话给你的查询方法,你可以做类似这样的
class Program {
static void Main(string[] args)
{
List<int> ints = new List<int>();
List<int> ints2 = new List<int>();
List<int> ints3 = new List<int>();
for (int i = 0; i < 5; ++i) ints.Add(i);
for (int j = 0; j < 5; ++j) ints2.Add(j);
for (int k = 0; k < 3; ++k) ints2.Add(k);
List<ICollection<int>> rets = GetRefs<int>(3, ints, ints2, ints3);
Console.WriteLine(string.Format("{0} out of {1} collections contain a reference to {2}", rets.Count, rets.Capacity, 3));
Console.ReadKey();
}
public static List<ICollection<T>> GetRefs<T>(T o, params ICollection<T>[] collections)
{
List<ICollection<T>> ret = new List<ICollection<T>>(collections.Length);
foreach (ICollection<T> obj in collections)
{
if (obj.Contains(o)) ret.Add(obj);
}
return ret;
}}
输出的东西去搜一下藏品是:2开出3集包含到3
参考不,除非对象o具有作为属性添加到的集合的集合。什么导致你达到这个要求?对于你的问题,可能会有更好的模式,我经常发现,当某种方法看起来过于困难时。 – Lazarus 2010-01-14 13:02:46
使用NHibernate并得到一个ObjectDeleteException - 出现时,简单地说,当我有两个或更多父母的子对象,我找不到另一个父对象。 – 2010-01-14 13:45:21