Adding POCO Entities

2019-08-16 17:06发布

问题:

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

I have one more EDMX with POCO files.

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

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

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

Any help would be appreciated.

回答1:

Solution was easy. Change the connectionstring of EDMX file.

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

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

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 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.

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.