question

DavidAnderson-4633 avatar image
0 Votes"
DavidAnderson-4633 asked DavidAnderson-4633 edited

Why is my new ADO.NET Entity Data Model not accessible via my VB.NET code?

I have just added a SQL Server database to an existing ASP.NET 4.8 Web Application website based on VB.NET. In the past, with another website, I made use of Linq-to-SQL to access a database, but the Entity Framework now appears to be the preferred solution. My next step was therefore to add the VB.NET version of the ADO.NET Entity Data Model to my App_Code folder, using the name SRMSEntityDataModel.

Via the Wizard, I chose EF version 6.x and the model contents option of 'EF Designer from database', selected the connection string for my database, chose to save connection settings in Web.Config as SRMSDBEntities, specified the tables I wanted to include and specified a model namespace of SRMSDBModel.

All went well as far as I could see. No error messages were generated and my tables all appeared on the SRMSEntityDataModel.edmx diagram.

My problem is that when I added the following line of code to one of my VB code pages, I was told that SRMSDBEntities is not defined.

 Using myEntities As New SRMSDBEntities()

I'm guessing this is a namespace issue but I have failed to find a solution. Adding 'Imports SRMSEntityDataModel' or 'Imports SRMSDBModel' to the top of the VB page simply generates another error message indicating that neither of these namespaces contains any public member or cannot be found.

Any assistance would be much appreciated.




dotnet-entity-framework
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DavidAnderson-4633 , based on my test, I reproduced your problem. I also could not reference the SRMSDBEntities class from the App_Code folder. I recommend that you could report a problem in Developer Community.


0 Votes 0 ·

As recommended, I have now raised this as a problem in the Developer Community.

0 Votes 0 ·
SimpleSamples avatar image
0 Votes"
SimpleSamples answered DavidAnderson-4633 commented

Did you do a build? Sometimes it is necessary to do a build for Visual Studio to find stuff.

In Visual Studio go to "View" | "Class View". Look around in there for SRMSDBEntities. When you find it you will know exactly what you need for accessing it.

See Database First - EF6.


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

A rebuild didn't help, but checking Class View provided a clear indication of where the problem might lie. For reasons I don't yet understand, SRMSDBEntities and associated objects related to my data tables are all listed under 1_App_Code, while the rest of my Web Application is listed under SRMS.

This prompted me to try adding 'Imports 1_App_Code.SRMSDBEntities', but that didn't fix my problem. It generated no less than three errors: Imports statement is unnecessary, Identifier expected, and Syntax error.

The Error List in VS2019 also lists several errors in SRMSEntityModel.Context.vb, which is shown as as belonging to the 1_App_Code project instead of the SRMS project.

0 Votes 0 ·
DavidAnderson-4633 avatar image
0 Votes"
DavidAnderson-4633 answered DavidAnderson-4633 edited

As an experiment, I installed the ADO.NET Entity Data Model code in the root of the project file, instead of in the App_Code subfolder. On this occasion, I had no namespace issues with the following line of code.

Using myEntities As New SRMSDBEntities()

I then repeated the exercise by adding the Entity Data Model code to a newly-created subfolder. This also worked without any problems.

The namespace issue therefore only appears to occur when you choose to add the ADO.NET Entity Data Model code to the App_Code sub-folder.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.