asp.net网站SQL71501 ::查看:[dbo]。[UsersView]包含对象的未解析引用

时间:2016-06-30 12:10:22

标签: c# linq sqlclr sql-view asp.net-profiles

我试图根据link查询asp.net网站中的个人资料表的属性。首先,我定义了一个CLR函数:

using System.Collections;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.Linq;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;

/// <summary>
/// Summary description for UserDefinedFunctions
/// </summary>
public class UserDefinedFunctions
{
    private static readonly Regex ProfileRegex = new Regex(@"([a-zA-Z]+):[A-Z]:(\d+):(\d+)");

[SqlFunction(FillRowMethodName = "FillProfileRow", TableDefinition = "Property nvarchar(250), Value nvarchar(2000)")]
public static IEnumerable ParseProfileString(SqlString names, SqlString values)
{
    var dict = ProfileRegex
        .Matches(names.Value)
        .Cast<Match>()
        .ToDictionary(
            x => x.Groups[1].Value,
            x => values.Value.Substring(int.Parse(x.Groups[2].Value), int.Parse(x.Groups[3].Value)));

    return dict;
}

public static void FillProfileRow(object obj, out string Property, out string Value)
{
    var x = (KeyValuePair<string, string>)obj;
    Property = x.Key;
    Value = x.Value;
}
}

但是当我尝试创建一个视图时,我收到一个错误,即CLR函数(ParseProfileString)是一个未解析的引用。

CREATE VIEW UsersView
AS
SELECT *
FROM (
    SELECT u.UserId
        ,u.Username
        ,m.Email
        ,f.Property
        ,f.Value
     FROM aspnet_Profile p
    INNER JOIN aspnet_Users u ON p.UserId = u.UserId
    INNER JOIN aspnet_Membership m ON m.UserId = u.Userid
    INNER JOIN aspnet_Applications a ON a.ApplicationId = m.ApplicationId
    CROSS APPLY ParseProfileString(p.PropertyNames, p.PropertyValuesString) f
    WHERE a.ApplicationName = 'MyApplication'
    ) src
pivot(min(value) FOR property IN (
        -- list your profile property names here
        FirstName, LastName, BirthDate
        )) pvt

0 个答案:

没有答案