2015-05-27 78 views
0

以下CLR函數的構建將在自動生成的SQL中獲得以下錯誤/* Error: Unsupported type. */。哪種類型導致了問題?以MSDN文檔https://msdn.microsoft.com/en-us/library/ms131103.aspx爲例來創建Clr函數。CLR功能不支持的類型

-------------------------------------------------------------------------------- 
--  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]; 

以下是C#代碼。

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); 
} 
+0

您可以發佈確切的錯誤嗎?數量,嚴重程度,狀態,消息。 –

+0

錯誤被嵌入到visual studio中生成的代碼中(問題中代碼的第一個塊)。然後它在'AS'下有錯誤,因爲沒有主體。 – ca9163d9

+0

它看起來像C#回饋4個輸出,而功能只設置爲3。是嗎? – SQLHound

回答