如何使用poco实体生成器

我正在使用VS2010,我已下载C#POCO实体生成器并安装它,现在我想使用它。

我无法阅读完整的 1 ,我找不到任何其他好的东西,所以我自己去了 – 我已经创建了一个模型然后我正在创建新的POCO实体,但我得到了波纹管错误:

Error 1 Running transformation: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.IO.FileNotFoundException: Unable to locate file at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path) at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.DynamicHost.ResolvePath(String path) at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.MetadataLoader.TryCreateEdmItemCollection(String sourcePath, String[] referenceSchemas, EdmItemCollection& edmItemCollection) at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.MetadataLoader.CreateEdmItemCollection(String sourcePath, String[] referenceSchemas) at Microsoft.VisualStudio.TextTemplatingA9DB2432A51EA8D42A615FBEB2ECB4E5.GeneratedTextTransformation.TransformText() at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result) 

问题是什么? 我认为它无法找到模型映射,如果是这种情况,我该如何解决?

1:由于我家乡的互联网限制。

查看本文以获取错误说明以及如何处理它。 从Visual Studio中的“添加项”创建POCO模板时,这是路径替换的问题。

当TT文件中EDMX文件的路径不正确时,会发生此错误。 要解决此问题,请打开TT文件,然后使用EDMX文件的相对路径手动替换路径。

例如,改变这个:

 string inputFile = @"Db.edmx"; 

这样的事情:

 string inputFile = @"..\DataAccess\Db.edmx"; 

如entityframeworktutorial中所述 ,在POCO实体生成之前,请禁用默认代码生成,该生成在Model1.designer.cs中生成Context和Entities代码。 要禁用默认代码生成,请右键单击.edmx,选择属性,然后删除“自定义工具”属性值“EntityModelCodeGenerator”的值。 现在右键单击设计器表面,选择“添加代码生成项…”并继续执行之前的操作