EffiProz 1.1 supports CLR Table-Valued Functions in a way that is very similar to how TVFs are supported by SQL Server. Following example shows how to create a TVF in effiproz database.
First write the CLR function,
public class IdNameEntry
{
public int Id { get; set; }
public string Name { get; set; }
public IdNameEntry(int id, string name)
{
Id = id;
Name = name;
}
}
public class TVFFunctions
{
[SqlFunction(FillRowMethodName = "FillRow")]
public static IEnumerable InitMethod()
{
List list = new List();
list.Add(new IdNameEntry(0, "car"));
list.Add(new IdNameEntry(1, "van"));
list.Add(new IdNameEntry(2, "bus"));
return list;
}
public static void FillRow(Object obj, out int? id, out string name)
{
IdNameEntry idNameEntry = (IdNameEntry)obj;
id = idNameEntry.Id;
name = idNameEntry.Name;
}
}
Now we create the TVF and execute as below,
CREATE FUNCTION testTVF() RETURNS TABLE (id INT, name VARCHAR(100)) EXTERNAL NAME ' EffiProz.Test.SelfTest.TVFFunctions.InitMethod'; SELECT id,name FROM testTVF();
Not sure whether my recent post made it here or not, so apologies for re-posting.
ReplyDeleteI'm trying to repeat this behaviour, and an exception is thrown once the TVF is called which indicates that either the obect doesn't exist, or my user doesn't have privileges. I'm running as sa.
Any help?