开发者

How to set ReturnType of FunctionImport to object that defined in other edmx file?

I have FunctionImport in one edmx1 file and I want to set the ReturnType to object that is located in other edmx2 file.

for example, I have edmx1 file with following FunctionImport and t_Page object defined in edmx1 file

edmx1

<FunctionImport Name="CopySite" EntitySet="t_Page" ReturnType="Collection(Entities.t_Page)">
       <Parameter Name="assemblyId" Mode="In" Type="Int32" />
       <Parameter Name="projectId" Mode="In" Type="Int32" />
</FunctionImport>

Now, I want to change the ReturnType, so it will return c_Page(declared in edxm2) instead of t_Page. If I just change t_Page to c_Page in edmx1 I get error that c_Page is not defined in edmx

<FunctionImport Name="CopySite" EntitySet="c_Page" ReturnType="Collection(Entities.c_Page)">
       <Parameter Name="assemblyId" Mode="In" Type="Int32" />
       <Parameter Name="projectId" Mode="In" Type="Int32" />
</FunctionImport>

How I can do this?

UPDATED

The reason why I need this is: I have several DBs with different tables except 5 of them that has same scheme but different names in each DB(e.g. c_Page,d_Page,e_Page...). It has to be with di开发者_JS百科fferent names! Now, when I create edmx for each DB I don't want to have hundreds of "same" classes, because they all have the same scheme but different names, so I want map the same class to all those tables

Maybe I need Entity Framework 4 “Code-First”? But in this way I need to create classes manually, right?

Can you suggest me how I can do this?


This is normally not possible. You can use only types defined within same EDMX file.

The only situation when this can be possible is described in this article where you are able to include one CSDL file into another. This would allow you defining entity in one CSDL file and include that CSDL file to second EDMX where you will be able to define FunctionImport and hopefully also used that entity (I didn't tested it). But it has some consequences:

  • Only CSDL files can be divided this way
  • You still need single shared MSL and SSDL file for both CSDL files
  • You cannot use EDMX (container for these files) any more
  • You cannot use designer and related automated tools and wizards

Edit:

So based on your edit you must have entities defined in every EDMX - there is no way how to avoid that. If you ensure that entities will be exactly same in every EDMX (including: names, keys, property names, relations) you can modify your T4 templates used to generate classes so that only one template generate them. After that you would need to ensure that ObjectContext derived classes generated by templates use correct classes in their exposed sets. It is all about some modifications in T4 templates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜