WPF object cannot create an objectset view?

I added a database view for my entity model. Now I'm trying to put an ObjectSet in my ObjectContext so that I can access the view in my application.

For regular tables, my ObjectSet will look like this:

 private ObjectSet<StarVendor> _StarVendor; public ObjectSet<StarVendor> StarVendor { get { if ((_StarVendor == null)) { _StarVendor = base.CreateObjectSet<StarVendor>("Stratus_X_TestEntities.StarVendors"); } return _StarVendor; } } 

So, I did the same for my view:

 private ObjectSet<CatalogItemSearch> _CatalogItemSearch; public ObjectSet<CatalogItemSearch> CatalogItemSearch { get { if ((_CatalogItemSearch == null)) { _CatalogItemSearch = base.CreateObjectSet<CatalogItemSearch>("Stratus_X_TestEntities.CatalogItemSearch"); } return _CatalogItemSearch; } } 

But when the code runs, I get an exception:

System.InvalidOperationException "EntitySet Name" Stratus_X_TestEntities.CatalogItemSearch "Not Found"

I know that for presentation I do not need the add / update / delete functions that the ObjectSet provides.

Is there an alternative type of Set that I should use for this?

or can this error come from something completely unrelated to what its appearance is?

thanks

+5
source share
2 answers

I would like to point out that the ObjectSet API, as well as the ObjectContext API, is an old Entity Framework API that is not commonly used today.

This was part of Entity framework 4.0, which was a long time ago (see Wikipedia: Entity Framework infrastructure history ).

Entity 4.1 was released in 2011, and from now on it is recommended to use the DbSet and DbContext . The current version of the finished version of the entity framework is version 6, and version 7 works.

I recommend you switch to Entity framework 6, which you can install in your Visual Studio project using Nuget: EntityFramework 6.1.3

Here's an article that has a chapter on the differences that the DbSet API provides compared to the old API. Take a look at the “Introducing DbContext and DbSet” chapter.

+2
source

If you use CodeFirst, you can always display the view when the table is displayed (using DbSet), and then it should work.

+1
source

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


All Articles