EntityFramework-Reverse-POCO-Code-First-Generator
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard
Can't map view with recursive join
Ambient :
- DB SqlServer
- EF6 (6.4.4 version)
Consider the table "Articles" (the creation script below) and the View "v_Articles" (the creation script below), that contains a recursion on the Articles table. Trying to generate the POCO classes, the EF will generate a correct WVN_v_Article class for the each row of the view, but in the extended DbContext class I can't find the line
public DbSet<WVN_Article> WVN_v_Articles { get; set; } // v_Article
Thanks Gabriele
Script:
CREATE TABLE WVN.Articles
(
PK_Article INT IDENTITY(1, 1) NOT NULL,
FK_Factory UNIQUEIDENTIFIER NOT NULL,
FK_ArticleLevel INT NOT NULL,
FK_ParentArticle INT NULL,
Code NVARCHAR(20) NOT NULL CONSTRAINT PK_Articles PRIMARY KEY CLUSTERED (PK_Article ASC),
CONSTRAINT UK_Articles UNIQUE NONCLUSTERED (FK_Factory ASC, FK_ArticleLevel ASC, Code ASC)
);
GO
CREATE VIEW WVN.v_Articles
AS
WITH TabRecursive AS
(
SELECT ItemP.PK_Article,
ItemP.FK_Factory,
ItemP.FK_ArticleLevel,
ItemP.FK_ParentArticle,
ItemP.Code,
CONVERT(NVARCHAR(100), ItemP.Code) AS FullCode
FROM WVN.Articles ItemP
WHERE ItemP.FK_ParentArticle IS NULL
UNION ALL
SELECT Item.PK_Article,
Item.FK_Factory,
Item.FK_ArticleLevel,
Item.FK_ParentArticle,
Item.Code,
CONVERT(NVARCHAR(100), CONCAT(Parent.FullCode, '/', Item.Code)) AS FullCode
FROM WVN.Articles Item
INNER JOIN TabRecursive Parent
ON Parent.PK_Article = Item.FK_ParentArticle
)
SELECT T.PK_Article,
T.FK_Factory,
T.FK_ArticleLevel,
T.FK_ParentArticle,
T.Code,
T.FullCode
FROM TabRecursive T;
GO