Previous articlesArticleI briefly introduced the concept of Entity Framework and introduced database first and model first instances. Today we will introduce another exciting development method: codeonly! Of course, EF's support for poco (plain old CLR object) is a major feature in ef4.0. It is also a major improvement in EF scalability. This is also a simple demonstration of the operation steps! Let's brie
model and the conceptual model.
Important classes:
1. objectcontext: objectcontext encapsulates the connection between. NET Framework and the database. This type is used as the gateway for "CREATE", "read", "Update", and "delete" operations.
2. objectquery: There is a useful method totracestring (). This method is used to track the executed SQL statements. Through this method, we can obtain the executed SQL statements, so that we can view and analyze
include a customer instance.
Because the definition of the bank account class does not contain the instance of the customer class, we need to set this one-to-one relationship in the configuration method of the customer class.
public class CustomerEntityConfiguration:EntityTypeConfiguration
Hasoptional in the customer class means that the customer class can have or have no bank account. When we use hasoptional to specify the relationship between the customer and the bankaccount class,
:", root.Name); foreach (var sub in context.GetSubCategories(root.CategoryId)) { Console.WriteLine("\t{0}", sub.Name); } }
The output of code list 6-16 is as follows:
Parent category is Books, subcategories are: Fiction Non-Fiction History Novel
Principle
The Entity Framework supports self-reference as
data Base service of your choice.
MySQL connector.net 6.9.4 or higher, downloadable from the official site or using NuGet.
Step 1. Creating a new Web applicationLet's start Visual Studio and create a new C # project just like that: In the following screens we ' re gonna choose the MVC template, then we ' re-click to the Change Authentication ... button where W E can choose if we want to enable authentication mechanism or not. The answer here depends on the features we need to has the
Before writing: I want to decompile system. Data. entity. dll (4.0 version) through refector, and find that only the attribute declaration and method declaration are decompiled.CodeNone of them. It's a big deal. I tried a few. the same is true for other net4.0 DLL files, and the refector on my machine is the latest version. Later I thought the dll path was incorrect and I referenced C: \ Program Files \ reference assemblies \ Microsoft \
concurrency, you can use database locks, known as pessimistic concurrency. For example, when you read a record from a database, you can lock it to read-only or update the state. If you lock a record to an updated state, other users will not be able to lock the record again, whether it is a read or update operation. If you lock a record as read-only, other people can lock it as read-only, but not update the operation.Management locks also have drawbacks, which can lead to more complex programmin
data to migrate.TestRun the project, try to access different pages, everything works fine.Open the Server Explorer, expand Data Connections\schoolcontext \tables, and you can see that the student and instructor tables have been replaced by the person table, open the person table, You can see that the table has all the columns of the Student and instructor tables.Right-click Show table data on the person table to view the discriminator columnHere's the new School database schemadeploy to Windows
://*/oraclemodel.csdl|res://*/oraclemodel.ssdl|res://*/oraclemodel.msl;provider= Oracle.manageddataaccess.client;provider connection String=quot;data SOURCE=127.0.0.1:1521/DJD; Password=lovemary; USER id=systemquot; "ProviderName= "System.Data.EntityClient"/> Addname= "Oracledbcontext"ProviderName= "Oracle.ManagedDataAccess.Client"connectionString= "User id=oracle_user; Password=oracle_user_password;data source=oracle "/> the EF assembly of Oracle can be understood as a driver - invar
Label:Original: http://www.cnblogs.com/dudu/archive/2011/12/27/entity_framework_sys_databases.html The "Trespass sys.databases" here refers to a query initiated by the Entity Framework by default: SELECT Count (*) from sys.databases WHERE [name]=n ' database name ' Note: This article is for the Entity
shown in.
Add the "ADO. NET Entity Data Model" project to the efmodel project, as shown in:
Set the name to "northwindef. edmx" and click "add ". Then, in the subsequent step, after selecting "northwind" for the database, select all the tables, attempts, and stored procedures as the shadow object, and save the default values for all other objects. Shows the final result.
Now, the data model i
If you have not touched on or do not know what Entity Framework is, please refer to some basic concepts and operation methods of the Entity Framework here. In a word, Entity Framework is a new data operation
Recently, I used ASP. net mvc Entity Framework to develop some projects, which makes it very easy to use. As a result, I have witnessed the development of Microsoft technology:
-In this figure, we can clearly see the changes in data access methods.
If you want to know about ADO. NET Entity Framework, you can directly
condition contains.
There are some different synthesis methods on this topic:
Execute two independent queries: one query movie and one query reviews, and then let the association combination complete the rest of the work.
Execute a select multiple types query as shown in this figure.
Sort Association-see Tip 1
Once you understand how a link combination works, you can make full use of it.
Enjoy.
Tip 38.How to Use Code only in the Data Se
using asynchronous and stored procedures for asp.net MVC applications
This is the translation of the Microsoft Official tutorial Getting started with Entity Framework 6 Code The 5 series, this is Nineth: using asynchronous and stored procedures for ASP.net MVC applications
Original: Async and Stored procedures with the Entity
databaseCSDL conceptual model: primarily for entity classes in applications, so this file typically describes entity classes, such as what properties are in a class, what type of each property isMSL Mapping: This file is mainly the database to the entity class to correspond, such as the entity class of a property corr
1. Installing the Entity FrameworkUse NuGet to install the Entity Framework Package: tools, library Package Manager, and Package Manager console, execute the following statement:Pm> Install-package EntityFramework2. Entity Framework Database Connection ConfigurationAfter the
In the previous article, I mentioned that "for cross-database queries, we have not found a method implemented through LINQ to entities ". Later I think about it. Theoretically speaking, it is not difficult to implement cross-database queries. Compared with non-Cross-database queries, I only have one more database name, for example, the following non-Cross-database query statement:
Select[Text]FromDBO. blog_postbodyWhereID=3560
Cross-database query
. Complete (); } } } }
7. view the T-SQL Statement of LINQ
?
123456789
var q = from P in context. products where p. productname. startswith ( "foo" ) select P; // before string commandtext = (objectquery
) q ). totracestring ();
// After string commandtext = Q. totracestring ();
VIII. Conclusion
Using EF for projects is also a problem that is easy to solve.
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.