CLR功能不支持的类型

时间:2015-05-27 20:22:41

标签: sql-server sqlclr

构建以下CLR函数将在自动生成的SQL中收到以下错误-------------------------------------------------------------------------------- -- This code was generated by a tool. -- -- Changes to this file may cause incorrect behavior and will be lost if -- the code is regenerated. -------------------------------------------------------------------------------- CREATE FUNCTION [dbo].[InitMethod] (@path [nvarchar](MAX), @pattern [nvarchar](MAX), @recursive [bit]) RETURNS /* Error: Unsupported type. */ AS EXTERNAL NAME [ListFiles].[FileList].[InitMethod]; 。哪种类型引起了问题? MSDN文档https://msdn.microsoft.com/en-us/library/ms131103.aspx用作创建Clr函数的示例。

public class FileInf
{
    public string Name { get; set; }
    public DateTime LastWriteTime { get; set; }
    public long Length { get; set; }
    public bool IsFile { get; set; }
};

[SqlFunction(FillRowMethodName = "FillRow")]
public static IEnumerable InitMethod(string path, string pattern, bool recursive)
{
    var dir = new DirectoryInfo(path);
    var files = dir.GetFiles(pattern, recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);
    foreach (var f in files)
    {
        yield return new FileInf
        {
            Name = f.Name,
            LastWriteTime = f.LastWriteTime,
            Length = f.Length,
            IsFile = (f.Attributes & FileAttributes.Directory) == FileAttributes.Directory ? false : true
        };
    }
}

public static void FillRow(Object obj, 
  out SqlChars name, 
  out SqlDateTime lastWriteTime, 
  out SqlInt64 Length, 
  out SqlBoolean isFile)
{
    var fileInfo = (FileInf)obj;
    name = new SqlChars(fileInfo.Name);
    lastWriteTime = new SqlDateTime(fileInfo.LastWriteTime);
    Length = new SqlInt64(fileInfo.Length);
    isFile = new SqlBoolean(fileInfo.IsFile);
}

以下是C#代码。

{{1}}

1 个答案:

答案 0 :(得分:0)

将您的属性更改为[SqlFunction(FillRowMethodName = "FillRow", TableDefinition = "[name] VARCHAR(MAX),[lastWriteTime] DATETIME2(7),[Length] BIGINT, [isFile] BIT")]

请参阅VS 2012 SSDT build CLR with IEnumerable failing on generated syntax