views:

21

answers:

0

Hello.
I'm trying to add an aggregation function into SQL server 2005 via C#. 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

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