添加 POCO 实体 [英] Adding POCO Entities

查看:29
本文介绍了添加 POCO 实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 context.tt 和 .tt 文件的 EDMX 文件.我在 .tt 文件下有 POCO 类.

I have an EDMX file with context.tt and .tt file. I have POCO classes under .tt file.

我还有一个带有 POCO 文件的 EDMX.

I have one more EDMX with POCO files.

我想将一些 POCO 类从 2nd EDMX 复制到 1st EDMX.

I want to copy some POCO classes from 2nd EDMX to 1st EDMX.

请记住,EDMX 中的表格是不同的.

Please keep in mind that the tables are different in both the EDMX.

只是想知道是否可以将一个 POCO 类从 EDMX 和 .tt 文件复制到另一个.

Just wanted to find out if its possible to copy one POCO class from EDMX and .tt file to another.

任何帮助将不胜感激.

推荐答案

解决方案很简单.更改 EDMX 文件的连接字符串.

Solution was easy. Change the connectionstring of EDMX file.

就我而言,我必须为同一个存储过程创建 2 个函数导入,每个导入指向不同的数据库.

In my case I had to create a 2 Function imports for same stored procedure, each pointing to different databases.

因此,我通过在模型浏览器中按住 rt 键单击存储过程创建了一个新的函数导入.

So I have created a new Function Import by rt-clicking on stored procedure in Model Browser.

在函数导入中,我们可以选择创建复杂类型.我需要创建一个新的 Complex 类型,因为存储过程中使用的一个表具有不同的列.

In Function Import we have option of creating Complex type. I needed to create a new Complex type since one table used in stored proc was having different columns.

创建函数导入后,只需关闭模型浏览器并构建解决方案.

Once the Function import is created, just close the Model browser and build the solution.

IDE 将提示输入文件名并创建新的 context.tt 和 .tt 文件.只需将新的 POCO 实体复制到现有的 .tt 文件中即可.

IDE will prompt for file name and new context.tt and .tt file will be created. Just copy the new POCO entities to the existing .tt file.

现在我们有 2 个函数导入和 2 个 POCO 实体.现在我们可以指向任何一个数据库,事情就可以工作了.

Now we have 2 Function Imports and 2 POCO enties. Now we can point to either of Databases and things would work.

希望对陷入类似情况的人有所帮助.

Hope that helps for anyone stuck in similar scenario.

这篇关于添加 POCO 实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆