开发者

Adding postgresql function in Devart Entity Model

I'm trying to import a postgresql function in an devart entity model, where I want to return a "custom" table, but I just can't get it working

I define my function like this:

CREATE OR REPLACE FUNCTION "GetJournalEntriesByVoucherId"(bigint)
  RETURNS SETOF record AS
$BODY$
SELECT 
    JE."JournalEntryID"
    JE."Amount",
    JE."EntryText",
FROM
    "JournalEntries" AS JE
WHERE
    JE."FK_Voucher"=$1
$BODY$
  LANGUAGE sql VOLATILE STRICT
  COST 100
  ROWS 1000;
ALTER FUNCTION getjournalentriesbyvoucherid(bigint) OWNER TO sqluser;

And used the steps in post #2 in http://www.devart.com/forums/viewtopi开发者_StackOverflow中文版c.php?p=71252 but I get the error message

The data reader is incompatible with the specified Model.Entity1. A member of the type, JournalEntryID, does not have a corresponding column in the data reader with the same name"


I've often had better luck using OUT variables for set-returning stored procedures. I don't know if this will help in your case, but you might try it. I honestly don't know if this changes the way the function works or just the way it's defined...

CREATE OR REPLACE FUNCTION "GetJournalEntriesByVoucherId"(BIGINT,
    JournalEntryID OUT DATATYPE,
    Amount OUT INT,
    EntryText OUT VARCHAR,
)
RETURNS SETOF record AS
$BODY$
....


@Flimzy is correct.
When a function returns setof record the reader returned from the function contains the record in form '(field1.Value, ..., fieldk.Value)' and is treated as varchar.
When out parameters are specified, the names and types of these parameters let the server know what the fields are in the reader, and the values are returned correctly. We have fixed some errors in this scenario in the latest 5.30.180 build, it works now.
The solution with strongly-typed setof (CompositeType) is an appropriate one as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜