The user control references Entity Framework and entityframework.

Source: Internet
Author: User

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> ();

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.