简体   繁体   English

在 VS2010 中将实体 Model 从一个项目复制到另一个项目

[英]Copy Entity Model from one project to another in VS2010

how can one copy Entity Framework model (edmx) from one WPF solution to another in VS 2010 ?如何在VS 2010中将实体框架 model (edmx) 从一个 WPF 解决方案复制到另一个解决方案? Simple Ctrl-C + Ctrl-V doesn't work.简单的 Ctrl-C + Ctrl-V 不起作用。

Copy it from the folder and place in another.从文件夹中复制它并放置在另一个文件夹中。 Then using Add >> Existing Items >>然后使用添加>>现有项目>>

Its wiser to regenerate in the new project in case if there are any other dependencies created elsewhere in application.如果在应用程序的其他地方创建了任何其他依赖项,则在新项目中重新生成更为明智。

Looks like you are trying to share EDMX between two solutions, aren't you?看起来您正试图在两个解决方案之间共享 EDMX,不是吗? In such case isn't it better to have EDMX, context and all entities in the separate assembly and share either compiled assembly or the whole project (add existing project to the second solution)?在这种情况下,在单独的程序集中拥有 EDMX、上下文和所有实体并共享已编译的程序集或整个项目(将现有项目添加到第二个解决方案)不是更好吗? You can also share the EDMX file itself by Add existing item as a link.您还可以通过将现有项目添加为链接来共享 EDMX 文件本身。 Anyway when adding the EDMX file to the second solution you will also need to add its .Designer.cs file (unless you are using T4 templates).无论如何,在将 EDMX 文件添加到第二个解决方案时,您还需要添加其.Designer.cs文件(除非您使用的是 T4 模板)。 For this you will have to edit .csproj file manually (open it as XML).为此,您必须手动编辑.csproj文件(以 XML 格式打开)。 Make sure that your .csproj file contains sections like:确保您的.csproj文件包含以下部分:

<ItemGroup>
    <Compile Include="Model.Designer.cs">
        <AutoGen>True</AutoGen>
        <DesignTime>True</DesignTime>
        <DependentUpon>Model.edmx</DependentUpon>
    </Compile>
    <!-- other files included in the project -->
</ItemGroup>
<ItemGroup>
    <EntityDeploy Include="Model.edmx">
        <Generator>EntityModelCodeGenerator</Generator>
        <LastGenOutput>Model.Designer.cs</LastGenOutput>
    </EntityDeploy>
 </ItemGroup>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM