插入视图不返回主键

Insert into view not returning primary key

我已将 POCO 映射到视图。当 EF 执行插入时,它会生成以下命令...

INSERT INTO "public"."vw_place"("Name","Description","Point") VALUES (,,) RETURNING "PlaceId"

但是代码,抛出以下错误...

{"A null store-generated value was returned for a non-nullable member 'PlaceId' of type 'DataAccess.Place'."}

这是执行插入的触发器函数...

CREATE OR REPLACE FUNCTION vw_place_dml()
  RETURNS trigger AS
$BODY$
                   BEGIN
                      IF TG_OP = 'INSERT' THEN

                        INSERT INTO tbl_place
                        (
                        "Name",
                        "Description",
                        "Point"
                    )
                    VALUES
                    (
                        NEW."Name",
                        NEW."Description",
                        ST_GeomFromWKB(NEW."Point", 4326)
                    );

                            RETURN NEW;

                            ELSIF TG_OP = 'UPDATE' THEN

                          UPDATE tbl_place SET
                        "PlaceId" = NEW."PlaceId",
                        "Name" = NEW."Name",
                        "Description" = NEW."Description",
                        "Point" = ST_GeomFromWKB(NEW."Point", 4326)
                    WHERE
                        "PlaceId" = OLD."PlaceId";

                            RETURN NEW;

                            END IF;
                            RETURN NEW;
                            END;
                $BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION vw_place_dml()
  OWNER TO postgres;

如果我 运行 在 pgAdmin 中 returns 什么都没有,这就是问题所在,但是该行已成功插入并生成了一个 PlaceId。

INSERT INTO "public"."vw_place"("Name","Description","Point") VALUES
('ergw','regr','\x0101000000000000009846b2bfe4e068d7ff33a73f')

RETURNING "PlaceId"

在触发器函数中插入之后 RETURN NEW; 之前,我添加了...

NEW."PlaceId" = currval('"tbl_place_PlaceId_seq"');