小编ITh*_*wer的帖子

NHibernate 3.1 Linq with Contains and Any

我们正在升级到NH3.1,这很顺利 - 就现有代码而言,一切正常.从2开始转向NH3的动机之一就是利用Linq的支持,并且通常它的工作非常好.但是我正在努力处理一些更复杂的where子句,特别是当我想根据子集合进行检查时:

var results = from r in registrations 
              where ( 
                         from p in persons 
                         where p.ExplicitManagers.Any(m => m.Manager == manager) 
                         select p 
                     ).Contains(r.Registrant) 
              select r; 
Run Code Online (Sandbox Code Playgroud)

模型所在的位置是:
pa Person和a registration r具有类型的注册人Person
p包含一组ExplicitManager关联实体,这些关联实体持有对另一个Person(管理者)的引用.

注意:注册是一个IQueryable<Registration>.Query()和一个人IQueryable<Person>.Query().
基本上我试图将注册限制在哪里person1 是一个明确的经理p.我可以通过连接而不是通过Contains子查询来完成此操作.

我收到以下错误:

"System.InvalidOperationException:Sequence包含多个匹配元素"

这样做作为子查询的原因是因为最终我需要外化逻辑以检查管理器使其可重用(实际上它更复杂但是我已经简化了这个例子,因为它是Any在一个Contains导致它的内部悲痛).

Contains在没有使用Any的子查询时似乎工作正常.这是我做错了什么,或者它是不支持的东西还是一个错误,还有另一种实现同样的方法吗?

非常感谢您提供的任何帮助.

linq nhibernate

8
推荐指数
1
解决办法
5037
查看次数

C#MD5哈希结果不是预期的结果

我已经尝试了我可以在网上找到的每个例子,但是我无法使用我的.NET代码从我的VB6应用程序生成相同的MD5哈希结果.

VB6应用程序产生与此站点相同的结果:http: //www.functions-online.com/md5.html

但是我无法在C#中使用相同的输入获得相同的结果(使用MD5.ComputeHash方法或FormsAuthentication加密方法)

请帮忙!!!!

根据要求,这里有一些代码.这是从MSDN直接推送的:

    public string hashString(string input)
    {
        // Create a new instance of the MD5CryptoServiceProvider object.
        MD5 md5Hasher = MD5.Create();

        // Convert the input string to a byte array and compute the hash.
        byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

        // Create a new Stringbuilder to collect the bytes
        // and create a string.
        StringBuilder sBuilder = new StringBuilder();

        // Loop through each byte of the hashed data 
        // and format each one as a hexadecimal string. …
Run Code Online (Sandbox Code Playgroud)

c# hash md5 cryptography

4
推荐指数
1
解决办法
8341
查看次数

SQL行到列

我有一个表,并希望将其行转置为列,类似于数据透视表但没有汇总.

例如,我有以下表格:

Question
--QuestionID
--QuestionText

Response
--ResponseID
--ResponseText
--QuestionID
Run Code Online (Sandbox Code Playgroud)

基本上我希望能够创建一个动态表,如:

Question 1 Text | Question 2 Text | Question 3 Text
---------------------------------------------------
Response 1.1 Text | Response Text 1.2 | Response 1.3
Response 2.1 Text | Response Text 2.2 | Response 2.3
Response 3.1 Text | Response Text 3.2 | Response 3.3
Response 4.1 Text | Response Text 4.2 | Response 4.3
Run Code Online (Sandbox Code Playgroud)

主要要求是我在设计时不知道问题文本是什么.

请有人帮忙 - 我把头发拉出来:oS

基本上,您可以保证在此方案中每个相应问题都会有响应.

sql-server pivot crosstab

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

crosstab ×1

cryptography ×1

hash ×1

linq ×1

md5 ×1

nhibernate ×1

pivot ×1

sql-server ×1