VIEWs in Entity-Framework?

I have a table called Item.

I have a view called ItemView that returns the entire column Item + another aggregated column that I want to read only.

I need to use it in the Entity Framework, and I don’t know how to use it, because when I insert a view into the constructor all the fields become essential keys, besides, there are no relationships, so I can’t access related tables as nav properties as from the base table.

Is there a way to make them both in the same class? what else can i do?

Say I have an Entity object. after saving this element I want to get my calculated values ​​from the view, how to do it?

I have never used Views in EF, what should be the best practice used in these scenarios?
Any tips, links, blogs, articles, jokes are welcome.

+3
source share
2 answers

In the end, I used this extension, which solved everything for me:

Frustrated by the lack of support for SQL views in the ADO.NET Entity-Framework Designer?

0
source

EF Designer automatically marks each NOT NULL field as part of the primary key. You will have to manually edit the edmx file and fix it. When the primary key is set correctly, you will need to determine the relationship between the table and the view itself. You should read this entry:

Entity Framework:

edmx , , . , :

select field_name from table_name 

select coalesce(field_name,null) field_name from table_name

, .

+5

Source: https://habr.com/ru/post/1727432/


All Articles