The user control references Entity Framework and entityframework.
Background:
When I was working on the software today, I encountered a problem. I added the Entity Framework to the project. There was no problem with the reference in the form code, and there was a problem with the reference in userControl.
I checked the app. config file
The file contains the connection string, but cannot be read.
Cause:
EF uses the App. Config ofCurrent application. That means that when you're designing the controls inside Visual Studio, it'll use devenv.exe. config. the connection isn' t listed there. also because DB access can have other side-effects (slow down the designer, cause unwanted DB queries), it's best to turn this off at design time.
Ef will call the app. config file in the design mode, but the vs configuration file is called at this time, of course, there is no connection string we want.
Solution:
Do not call ef during design.
Code:
if (DesignMode){ return;}using (var edm = new StudentManageEntities()){ //do something here}
C # entity framework Problems
Microsoft in. NET 3.5 launched Entity Framework, known as Microsoft in the future. NET, it will also become a technical solution for Microsoft to integrate data across all applications, with VS2010 and. NET 4.0, Entity Framework is more advanced to 4.0 (followed. in addition to providing a number of major new features, Microsoft also announced that EF will replace the development of LINQ to SQL and become the mainstream technology for database access.
In addition, do you have any value for your specific content? I cannot see it when you paste this code ~
Zhao Yuanyuan [authoritative expert]
Entity Framework Method for retrieving Objects Based on Generics
Using (AdventureWorksEntities context =
New AdventureWorksEntities ())
{
String queryString =
@ "Select value contact FROM AdventureWorksEntities. Contacts
AS contact WHERE contact. FirstName = @ fn ";
Var result =
(Context. CreateQuery <Contact> (queryString,
New ObjectParameter ("fn", "Frances"). AsQueryable <Contact> ();
}