cool hit counter EntityFramework Learning Notes - edmx files_Intefrankly

EntityFramework Learning Notes - edmx files


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/41627669

A brief introduction to Entity FrameWork was given above, here's a bit about the edmx file, the heart of EF.

Create edmx file in VisualStudio (this example environment is VisualStudio 2012)

1、newly built—ADO.NET the real thing (as opposed an image or model of it) data model:

2, when choosing the data model, because I have already created the table in the database before, so we choose to generate from the database first here (i.e. DB First), if you choose the empty model, you can generate the entity class and database table by creating the entity model first without creating the database.

3. Select the database connection.

4、 Select or set up a server to connect to、 Validation Information、 databases first name:

5. Note that because the connection string will be saved to the configuration file, select [Yes, include sensitive data in the connection string] here.

6、 Select the option we want to generate the real thing (as opposed an image or model of it) meters:

7、 After everything is done, as shown below,edmx Just already based on our chosen databases The table generates the corresponding the real thing (as opposed an image or model of it), at the same time, In the Solution Explorer, theT4 templatesModel.tt under also generates for the automatic weDepartment harmonyEmployee the real thing (as opposed an image or model of it) kind。

At this point, the edmx file has been created.

As mentioned above, an edmx file is essentially an XML file that is used to define conceptual models, storage models, and mappings between those models. While the edmx file opens by default as an entity designer, it can also be opened as an XML text editor by right-clicking on the Model.edmx file, at which point the edmx file can be seen in its true form as follows.

As you can see from the code, edmx consists roughly of three parts, SSDL, CSDL, and C-S, corresponding to for databases the real thing (as opposed an image or model of it)Mapping between database tables and entities These three areas of analysis,SSDL There is a pair of databases a table (listing information)、 Provisions for fields, etc.,CSDL There is a pair of the real thing (as opposed an image or model of it) first name、 the real thing (as opposed an image or model of it) Provisions for properties, etc.,C-S There is a pair ofMapping between database tables and entities。 in a nutshelledmx documents, is used to parse the storage model、 Conceptual models and the mapping between these two, It's actually the same detailed representation of that image above。

The seventh step above says that while generating the edmx template, the two classes corresponding to the entity Employee and Department are also generated, and in the parent of the entity class, there is a Model.tt, which is the T4 template, look at the following code in the T4 template, you will understand, in fact, these two entity classes are generated by the T4 template according to the edmx configuration file. (The code can be confusing when viewing T4 templates with VisualStudio, so you can install a plug-in for T4 Editor and then learn the T4 template code, download the plug-in at Click to jump

<#@ include file="EF.Utility.CS.ttinclude"#><#@ 
 output extension=".cs"#><#

const string inputFile = @"Model.edmx";
var textTransform = DynamicTextTransformation.Create(this);
var code = new CodeGenerationTools(this);
var ef = new MetadataTools(this);
var typeMapper = new TypeMapper(code, ef, textTransform.Errors);
var	fileManager = EntityFrameworkTemplateFileManager.Create(this);
var itemCollection = new EdmMetadataLoader(textTransform.Host, textTransform.Errors).CreateEdmItemCollection(inputFile);
var codeStringGenerator = new CodeStringGenerator(code, typeMapper, ef);

if (!typeMapper.VerifyCaseInsensitiveTypeUniqueness(typeMapper.GetAllGlobalItems(itemCollection), inputFile))
{
    return string.Empty;
}

WriteHeader(codeStringGenerator, fileManager);

foreach (var entity in typeMapper.GetItemsToGenerate<EntityType>(itemCollection))
{
    fileManager.StartNewFile(entity.Name + ".cs");
    BeginNamespace(code);
#>

Maybe it's because I've been talking English all day today and I'm so sleepy I can't keep my eyes open. Good Night!


Recommended>>
1、A mountain of internet a sea of information maintaining cyber security starts with me
2、Association News Βangladesh Organized a Symposium on Supply Chain Financial Services Outsourcing
3、The first in the country Hengrui CD47 monoclonal antibody enters phase I clinical
4、Continental and Huawei team up to test CV2X 2018 to push smart intersections in the US
5、What should I do if I want to watch a video but I encounter copyright restrictions

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号