本文介绍了C#和SQL Server 2008 CLR序列化问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在C#中创建一个 SqlUserDefinedAggregate 以附加到我的SQL Server 2008实例。我正在使用.NET 3.5。基本上,我想计算我看到字符串值的次数。由于使用的原因,它确实必须是一个聚合函数。该函数的代码在逻辑上是合理的,但是当我进行部署时,我得到了:

I am trying to create a SqlUserDefinedAggregate in C# to attach to my SQL Server 2008 instance. I am working with .NET 3.5. Basically, I want to count the number of times I see string values. It does need to be an aggregate function because of the use. The code for the function is logically sound, but when I go to deploy, I get this:

m_types Dictionary< string,int> 。我的代码的轮廓如下所示:

m_types is a Dictionary<string, int>. The outline of my code looks like this:

[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate (Format.Native)]
public struct CountTypes
{
    private Dictionary<string, int> m_types;

    public void Init ()
    {
        m_types = new Dictionary<string, int> ();
    }

    public void Accumulate (SqlString value) { ... }

    public void Merge (CountTypes group) { ... }

    public SqlString Terminate () { ... }
}


推荐答案

通常词典不是开箱即用的可序列化的,这是您的问题,有关如何解决此问题的文章很多,例如Adam Semel的。

usually a Dictionary is not out of the box serializable and this is your issue, there are plenty of articles on how to solve this issue, for example Adam Semel's How to Serialize a Dictionary or Hashtable in C#.

这篇关于C#和SQL Server 2008 CLR序列化问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:00