[英]List serialization in CLR aggregation function C#
I'm trying to add an aggregation function into SQL server 2005 via C#. 我正在尝试通过C#将聚合函数添加到SQL Server 2005中。 But when I deploy the project it fails with the following error: 但是当我部署项目时,它失败并显示以下错误:
.Net SqlClient Data Provider: Msg 6222, Level 16, State 1, Line 1 Type "AggregationTest.CountNonintersectingIntervals" is marked for native serialization, but field "intervals" of type "AggregationTest.CountNonintersectingIntervals" is not valid for native serialization .Net SqlClient数据提供程序:消息6222,级别16,状态1,行1类型“ AggregationTest.CountNonintersectingIntervals”类型已标记为本机序列化,但类型为“ AggregationTest.CountNonintersectingIntervals”的字段“ intervals”不适用于本机序列化
Here's the code I'm using: 这是我正在使用的代码:
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedType(Format.Native)]
public struct Interval : INullable
{
public Interval(int beginning, int ending) : this()
{
this.beginning = beginning;
this.ending = ending;
}
public override string ToString()
{
return "(" + beginning + ", " + ending + ")";
}
public bool IsNull { get { return m_Null; } }
public static Interval Null { get { /*Some code*/ } }
public static Interval Parse(SqlString s)
{
/*Some code*/
}
public int beginning;
public int ending;
private bool m_Null;
}
[Serializable]
[Microsoft.SqlServer.Server.SqlUserDefinedAggregate(Format.Native)]
public struct CountNonintersectingIntervals
{
public void Init()
{
intervals = new List<Interval>();
}
public void Accumulate(Interval interval)
{
intervals.Add(interval);
}
public void Merge(CountNonintersectingIntervals Group)
{
intervals.AddRange(Group.intervals);
}
public SqlInt32 Terminate()
{
// Some complicated calculation using intervals
}
private List<Interval> intervals;
}
Could you please help me to solve the problem 你能帮我解决问题吗
您必须将SqlUserDefinedAggregate
属性初始化为Format.UserDefined
并实现IBinarySerialize
接口,以照顾intervals
实例。
Native serialization is only valid for blittable types (which List<Interval>
is not). 本机序列化仅对可填充类型有效( List<Interval>
无效)。
http://social.msdn.microsoft.com/forums/en-us/sqlnetfx/thread/D4A58ABA-4C95-4232-AF6E-270892BE45C5 http://social.msdn.microsoft.com/forums/en-us/sqlnetfx/thread/D4A58ABA-4C95-4232-AF6E-270892BE45C5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.