【发布时间】:2020-08-03 22:17:22
【问题描述】:
我正在使用带有 EF6 的 PostgreSQL 12。我正在尝试将物化视图添加到我的模型中,但该视图未在模型向导中列出。我知道能够将视图添加到模型中,实体框架需要数据库视图中的至少一列不可为空。但我不知道该怎么做。
我尝试创建唯一索引和行号,但没有成功。
CREATE MATERIALIZED VIEW "Stock"
AS
SELECT coalesce(cast(ROW_NUMBER() OVER() as int), 0) as "Id",
"PartMaster"."PartID",
"OEMPart"."PartCatalogID",
"PartMaster"."PartCode",
"PartCatalog"."CustomPartCode",
"OEMPart"."OEMCode",
"PartMaster"."PartDesc",
"GoodsReceivedDetail"."Cost",
"GoodsReceivedDetail"."Markup",
"GoodsReceivedDetail"."SellingPrice",
coalesce("GoodsReceivedDetail"."Quantity", 0) as "InQuantity",
coalesce("InvoiceDetail"."Quantity", 0) as "OutQuantity",
coalesce("GoodsReceivedDetail"."Quantity", 0) - coalesce("InvoiceDetail"."Quantity", 0) as "StockQuantity"
FROM
"PartCatalog"
INNER JOIN
"PartMaster"
ON
(
"PartCatalog"."PartID" = "PartMaster"."PartID")
INNER JOIN
"OEMPart"
ON
(
"PartCatalog"."PartID" = "OEMPart"."PartID")
INNER JOIN
"GoodsReceivedDetail"
ON
(
"OEMPart"."PartCatalogID" = "GoodsReceivedDetail"."PartCatalogID")
LEFT OUTER JOIN
"InvoiceDetail"
ON
(
"GoodsReceivedDetail"."PartCatalogID" = "InvoiceDetail"."PartCatalogID")
INNER JOIN
"PartCategory"
ON
(
"PartMaster"."PartCategoryID" = "PartCategory"."PartCategoryID") ;
CREATE UNIQUE INDEX "Id"
ON "Stock" ("PartCatalogID");
【问题讨论】:
-
您的问题是如何确保您的物化视图中的一列不可为空?如果是这样,请查看stackoverflow.com/questions/47242219/…
标签: postgresql entity-framework materialized-views