How to: Use the Entity Framework Data Model Located in an External Assembly 如何:使用位于外部程序集中的EF数据模型
If you have a non-XAF application, and want to develop an XAF application that utilizes the same database, you can generate business classes for an existing database to achieve this task. However, if your existing application is based on the Entity Framework data model, you can reuse this model in XAF to avoid code duplication. This topic describes how to use the data model located within an external assembly.
如果您有一个非 XAF 应用程序,并且想要开发一个使用同一数据库的 XAF 应用程序,则可以为现有数据库生成业务类来实现此任务。但是,如果现有应用程序基于实体框架数据模型,则可以在 XAF 中重用此模型以避免代码重复。本主题介绍如何使用位于外部程序集中的数据模型。
Note 注意
If the external assembly is an XAF Module, then you do not need to follow this topic. Entities declared within XAF modules are automatically recognized and added to the Application Model.
如果外部程序集是 XAF 模块,则无需遵循本主题。在 XAF 模块中声明的实体将自动识别并添加到应用程序模型中。
1.Create a new XAF solution using the DevExpress v19.2 XAF Solution Wizard. Select Entity Framework Code First at the Choose ORM step and click Finish.
使用 DevExpress v19.2 XAF 解决方案向导创建新的 XAF 解决方案。在"选择 ORM"步骤中首先选择实体框架代码,然后单击"完成"。
2.Reference the external assembly that contains the Entity Framework data model to be used.
引用包含要使用的实体框架数据模型的外部程序集。
3.A DbContext class is required to use entities from the external assembly. To declare it, do one of the following.
使用外部程序集中的实体需要 DbContext 类。要声明它,可以执行以下操作之一。
- In the module project, inherit the DbContext declared in the external assembly.
- Add required entity types from the external assembly to the existing DbContext located in the BusinessObjects/MySolutionDbContext.cs(MySolutionDbContext.vb) file.
- 在模块项目中,继承在外部程序集中声明的 DbContext。
- 将所需的实体类型从外部程序集添加到位于业务对象/MySolutionDbContext.cs(MySolutionDbContext.vb)文件中的现有 DbContext。
4.Run the Module Designer. In the Exported Types section, expand the Referenced Assemblies node. Then, expand the node that corresponds to the external assembly. Select entities to add and press the SPACEBAR or use the Use Type in Application command from the context menu. The selected entities will be marked in bold. This means that they have been added to the Application Model, and will take part in the UI construction process.
运行模块设计器。在"导出的类型"部分中,展开引用程序集节点。然后,展开与外部程序集对应的节点。选择要添加和按下空格键的实体,或使用上下文菜单中的"在应用程序中使用类型"命令。所选实体将以粗体标记。这意味着它们已添加到应用程序模型中,并将参与 UI 构造过程。
Note 注意
Alternatively, you can add entities in code. Open the Module.cs (Module.vb) file and add the required entity types to the ModuleBase.AdditionalExportedTypes collection in the module's constructor.
或者,您可以在代码中添加实体。打开Module.cs (module.vb) 文件,并将所需的实体类型添加到模块基础。附加导出类型集合中的模块构造函数。
5.Rebuild your solution, so that the changes made in the Designer are loaded to the Application Model, and run the Model Editor. Make sure that the entities added in the previous step are available in the BOModel node.
重新生成解决方案,以便将设计器中所做的更改加载到应用程序模型,并运行模型编辑器。确保上一步中添加的实体在 BOModel 节点中可用。
6.Add navigation items for the added entities by following the steps described in the Add an Item to the Navigation Control tutorial.
按照"将项目添加到导航控制"教程中所述的步骤,为添加的实体添加导航项。
7.Ensure that the correct DbContext type is passed to the application's Object Space Provider in the CreateDefaultObjectSpaceProvider method located in WinApplication.cs (WinApplication.vb) and WebApplication.cs (WebApplication.vb) files. For details, refer to the Specify the Entity Container (Context) section of the Use the Entity Framework Data Model topic.
确保将正确的 DbContext 类型传递到位于WinApplication.cs (WinApplication.vb) 和WebApplication.cs (WebApplication.vb) 文件中的"创建默认对象空间提供程序"中的应用程序的对象空间提供程序。有关详细信息,请参阅使用实体框架数据模型主题的"指定实 体容器(上下文)"部分。
How to: Use the Entity Framework Data Model Located in an External Assembly 如何:使用位于外部程序集中的EF数据模型的更多相关文章
- [转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)
本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-a ...
- How to: Supply Initial Data for the Entity Framework Data Model 如何:为EF数据模型提供初始数据
After you have introduced a data model, you may need to have the application populate the database w ...
- 第三篇:Entity Framework CodeFirst & Model 映射 续篇 EntityFramework Power Tools 工具使用
上一篇 第二篇:Entity Framework CodeFirst & Model 映射 主要介绍以Fluent API来实作EntityFramework CodeFirst,得到了大家一 ...
- 第二篇:Entity Framework CodeFirst & Model 映射
前一篇 第一篇:Entity Framework 简介 我有讲到,ORM 最关键的 Mapping,也提到了最早实现Mapping的技术,就是 特性 + 反射,那Entity Framework 实现 ...
- Entity Framework : The model backing the '' context has changed since the database was created
1.采用code first 做项目时,数据库已经生成,后期修改数据库表结构.再次运行时出现一下问题: Entity Framework : The model backing the '' cont ...
- 【Entity Framework】Model First Approach
EF中的model first 所谓mf, 就是使用vs提供的edm designer去设计model,然后将设计好的model使用vs在指定的数据库中生成数据库即可. 当你的项目既没有数据库也没有c ...
- Entity Framework之Model First开发方式
一.Model First开发方式 在项目一开始,就没用数据库时,可以借助EF设计模型,然后根据模型同步完成数据库中表的创建,这就是Model First开发方式.总结一点就是,现有模型再有表. 二. ...
- How to: Use the Entity Framework Model First in XAF 如何:在 XAF 中使用EF ModelFirst
This topic demonstrates how to use the Model First entity model and a DbContext entity container in ...
- Entity Framework 5.0系列之EF概览
概述 在开发面向数据的软件时我们常常为了解决业务问题实体.关系和逻辑构建模型而费尽心机,ORM的产生为我们提供了一种优雅的解决方案.ADO.NET Entity Framework是.NET开发中一种 ...
随机推荐
- Flask 蓝图机制及应用
我们都知道 flask 是一个轻量级的 web 框架,相对于其他同类型框架更为灵活.轻便.安全且容易上手.开发者可以随意编写自己想要的项目结构,同时还有很多的第三方库供君选择.但是灵活的同时也带来了相 ...
- 机器学习笔记(九)---- 集成学习(ensemble learning)【华为云技术分享】
集成学习不是一种具体的算法,而是在机器学习中为了提升预测精度而采取的一种或多种策略.其原理是通过构建多个弱监督模型并使用一定策略得到一个更好更全面的强监督模型.集成学习简单的示例图如下: 通过训练得到 ...
- Python装饰器总结,带你几步跨越此坑!
欢迎添加华为云小助手微信(微信号:HWCloud002 或 HWCloud003),输入关键字"加群",加入华为云线上技术讨论群:输入关键字"最新活动",获取华 ...
- luogu P1759 通天之潜水
题目背景 直达通天路·小A历险记第三篇 题目描述 在猴王的帮助下,小A终于走出了这篇荒山,却发现一条波涛汹涌的河拦在了自己的面前.河面上并没有船,但好在小A有n个潜水工具.由于他还要背重重的背包,所以 ...
- go基础之服务退出问题
最近学习公司微服务的代码,看到每一个微服务的main函数都阻塞在那里,然后里面起的goroutine一直在哪里运行. package main import( "fmt" &quo ...
- JavaScript基础3
While循环 在指定条件为真时循环执行代码块.先确定条件再执行代码 语法 while(条件) { 需要执行的代码 } 条件中所用变量如果没有值,循环就不会停下,会导致浏览器崩溃: do...whil ...
- openlayers6结合geoserver实现地图空间查询(附源码下载)
前言 之前写过一篇 openlayers4 版本的地图空间查询文章,但是由于是封装一层 js 代码写的,很多初学者看起来比较有点吃力,所以本篇文章重新写一篇地图空间查询文章,直接基于最新版本 open ...
- 第6节:Java基础 - 三大集合(上)
第6节:Java基础 - 三大集合(上) 本小节是Java基础篇章的第四小节,主要介绍Java中的常用集合知识点,涉及到的内容包括Java中的三大集合的引出,以及HashMap,Hashtable和C ...
- 2019企业linux运维最需要的了解的一些硬件基础知识
第3章 服务器 245 3.1 电脑的种类 245 3.2 服务器的介绍 246 3.2.1 服务器的类别 246 3.2.2 服务器的性能 247 3.2.3 服务器的 ...
- SpringBoot系列之Spring Data Jpa集成教程
SpringBoot系列之Spring Data Jpa集成教程 Spring Data Jpa是属于Spring Data的一个子项目,Spring data项目是一款集成了很多数据操作的项目,其下 ...