0

This table/view has been excluded. To use the entity, you will need to review your schema, add the correct keys, and uncomment it.

Here is my view:

WITH temptable (code, DataItem, description) AS 
(
    SELECT        
        code, 
        CAST(LEFT(description, CHARINDEX(CHAR(10), description + CHAR(10)) - 1) AS nvarchar(50)) AS Expr1, 
        CAST(STUFF(description, 1, CHARINDEX(CHAR(10), description + CHAR(10)), '') AS nvarchar(50)) AS Expr2
    FROM            
        dbo.book
    WHERE        
        (idbook = 1)

    UNION ALL

    SELECT        
        code, 
        CAST(LEFT(description, CHARINDEX(CHAR(10), description + CHAR(10)) - 1) AS nvarchar(50)) AS Expr1, 
        CAST(STUFF(description, 1, CHARINDEX(CHAR(10), description + CHAR(10)), '') AS nvarchar(50)) AS Expr2
    FROM            
        temptable AS temptable_2
    WHERE        
        (description > '')), 
testno AS
(
     SELECT code, DataItem
     FROM temptable AS temptable_1
)
SELECT TOP (100) PERCENT 
    REPLACE(testno_1.DataItem, '  ', ' ') AS predmet, 
    po.code, year, info
FROM            
    testno AS testno_1 
LEFT OUTER JOIN
    dbo.book AS book_1 ON testno_1.code = book_1.code 
LEFT OUTER JOIN
    dbo.Getbook AS po ON testno_1.code = po.code
ORDER BY 
    po.code

This problem is in my model.edmx, I need view to generate report, but when I try to update model and put entity in it, it showed me an error which I mention in title on the top.

My connection to the dbo is good everything is ok, so only problem is primary key for view. I know that primary key cannot be in view but I think that always exist solution.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Just forget you ever learned about "top (100) percent" - it does nothing useful. A view, like a table, has no defined order so stop trying to force an order in an effort to support lazy coding habits. – SMor Sep 14 '20 at 12:30
  • As per eltons comment here https://stackoverflow.com/questions/9415334/entity-framework-code-first-readonly-entity " In the view definition: SELECT NEWID() as [VirtualKey] ... In the Entity's Map: // Primary Key this.HasKey(t => t.VirtualKey); " – Nick.Mc Sep 14 '20 at 13:04
  • Or you could try using a Keyless entity type as per here: https://learn.microsoft.com/en-us/ef/core/modeling/keyless-entity-types?tabs=data-annotations _Usage Scenarios: Mapping to database views that do not contain a primary key_ – Nick.Mc Sep 14 '20 at 13:06

0 Answers0