SQL View -> Typed View not appearing in EF 6

Posts   
 
    
ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 13-Sep-2014 18:41:41   

EF 6, SQL Server 2012

My goal is to read from a View to support a Picker in the UI. Open to suggestions...

I have a SQL View comprised of keys mostly from many tables. This is to be a picker in the UI.

When I reverse engineer it to a Typed View and generate the code, the PersonPickerTypedView class is made, but there is no way to access it in the datacontext. It is not referenced in the data context

When I use a stored procedure to make a typed view, I get a GetMyProcTypedView() method generated. I assumed VIews would be the same?

How do I access the Typed View in EF 6?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 14-Sep-2014 11:32:48   

LLBLGen pro version? You mapped the view as a typed view? Typed views are not supported for EF unless they're returned by a proc as EF needs a PK on a type which is used as an entity. It's a bit odd that the typed view passed through the validator without being picked up as an error.

Frans Bouma | Lead developer LLBLGen Pro
ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 14-Sep-2014 21:42:20   

I use LLBL 4.2 with EF 6 against Sql Server 2012 Express

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Sep-2014 07:24:00   

At LLBLGen project you have selected EF as the target framework. Right? Did you try to retrieve the View data via a SP?

David Elizondo | LLBLGen Support Team
ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 15-Sep-2014 19:36:18   

I used a simple View, no SP. Then Right clicked the View in LLBL and reverse-engineered it. That's all.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Sep-2014 19:59:10   

Did you "Reverse Engineer to Entity Definitions" or "Reverse Engineer to Typed View"?

ianvink
User
Posts: 393
Joined: 15-Dec-2006
# Posted on: 15-Sep-2014 20:18:39   

I tried both. Both exported and compiled, but only when I exported to Entity did that work for the app.

I had to right click one of the fields and indicate it was the ID field to make the entity work.

I'd rather the picker not be an entity as it's read only, but I am using Entity as it works while the Typed view does not.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 16-Sep-2014 07:34:36   

ianvink wrote:

I tried both. Both exported and compiled, but only when I exported to Entity did that work for the app.

As Frans, mentioned, it's odd that LLBLGen Designer didn't popup any validation errors when you tried to generate the TypedView. It should report an error similar to:

Message type: Error Message text: For database 'SQL Server' the typed view 'Invoice' is mapped onto the target 'Northwind.dbo.Invoices', which is a View. A typed view mapped onto targets of type 'View' aren't supported as the Entity Framework can't deal with types without a PK, multiple types mapped onto the same target. Source: Project Validation Created on: ...

Maybe you need to update your LLBLGen Pro to the latest version.

ianvink wrote:

I had to right click one of the fields and indicate it was the ID field to make the entity work.

That's expected indeed.

ianvink wrote:

I'd rather the picker not be an entity as it's read only, but I am using Entity as it works while the Typed view does not.

You should do it via an Entity (with PK) or via a SP call, as TypedView is not supported (Ref...).

David Elizondo | LLBLGen Support Team