使用ADO.NET生成模板的问题DbContext Generator,抛出异常,.cs文件为空 [英] Problem generating templates using ADO.NET DbContext Generator, exception thrown, .cs files are empty

查看:102
本文介绍了使用ADO.NET生成模板的问题DbContext Generator,抛出异常,.cs文件为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的配置:

Visual Studio 2010版本10.0.30319.1 RTMRel,见KB2275326和KB982218

Visual Studio 2010 Version 10.0.30319.1 RTMRel wit KB2275326 and KB982218

.NET Framework版本。 4.0.30319.1 RTMRel

.NET Framework Version. 4.0.30319.1 RTMRel

已下载并安装了2011年2月14日创建的EF4FeatureCTP5.exe

Downloaded and installed EF4FeatureCTP5.exe created Feb 14, 2011

 

这是ADO.Net团队博客的演练:

Did this walkthrough from the ADO.Net team blog:

 

工作完美。

 

然后,在一个新项目中, 我尝试使用现有数据库生成我的edmx文件,如演练中的第3步中所示,完全遵循所有其他说明(三次)。

Then, in a new project,  I tried to use an existing database to generate my edmx file as indicated midway through step 3 in walkthrough, following all other instructions exactly (three times).

为了简单起见,我只包括一个小桌子。 以下是表格定义:

To keep things simple I included only one tiny table.  Here is the table definition:



CREATE TABLE [dbo]。[downloadSource](

    [ downloadSourceId] [int] IDENTITY(1,1)NOT NULL,

    [Name] [nvarchar](250)NOT NULL,

     [用户名] [nvarchar](250)空,

    [密码] [nvarchar](250)空,

     [ConnectionKey] [nvarchar](250)NULL,

    [Url] [nvarchar](250)NULL,

  CONSTRAINT [PK_downloadSource] PRIMARY KEY CLUSTERED



    [downloadSourceId] ASC

)WITH(PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF,IGNORE_DUP_KEY = OFF,ALLOW_ROW_LOCKS  = ON,ALLOW_PAGE_LOCKS  = ON)ON [PRIMARY]

)ON [PRIMARY]


CREATE TABLE [dbo].[downloadSource](
    [downloadSourceId] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](250) NOT NULL,
    [Username] [nvarchar](250) NULL,
    [Password] [nvarchar](250) NULL,
    [ConnectionKey] [nvarchar](250) NULL,
    [Url] [nvarchar](250) NULL,
 CONSTRAINT [PK_downloadSource] PRIMARY KEY CLUSTERED
(
    [downloadSourceId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

表在设计器窗口中看起来很好。

Table looks fine in designer window.

然而,当我尝试使用ADO.NET DbContext生成器添加新项目Visual C#Items

However, when I try to add a new item using the ADO.NET DbContext Generator Visual C# Items

在添加时我收到以下错误:

as soon as I click on add I get the follow error:

错误    1   正在运行的转换:System.Reflection.TargetInvocationException:调用目标已抛出异常。 ---> System.IO.FileNotFoundException:无法找到文件

  在Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)

  在Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolvePath(String path)

   ---内部异常堆栈跟踪结束---

  在System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo方法,Object target,Object []参数,SignatureStruct& sig,MethodAttributes methodAttributes,RuntimeType typeOwner)

   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo方法,Object target,Object []参数,Signature sig,MethodAttributes methodAttributes,RuntimeType typeOwner)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object [] parameters,CultureInfo culture,Boolean skipVisibilityChecks)

  在System.Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)

  在Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.DynamicHost.ResolvePath(String path)

  在Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.MetadataLoader.TryCreateEdmItemCollection(String sourcePath,String [] referenceSchemas,EdmItemCollection& edmItemCollection)

  在Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.MetadataLoader.CreateEdmItemCollection(String sourcePath,String [] referenceSchemas)

  在Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.TransformText()

  在Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session,String source,ITextTemplatingEngineHost host,String& result)        1    1

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.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.DynamicHost.ResolvePath(String path)
   at Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.MetadataLoader.TryCreateEdmItemCollection(String sourcePath, String[] referenceSchemas, EdmItemCollection& edmItemCollection)
   at Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.MetadataLoader.CreateEdmItemCollection(String sourcePath, String[] referenceSchemas)
   at Microsoft.VisualStudio.TextTemplating5D13A38739BCCEF40747B2CA6C4AA978.GeneratedTextTransformation.TransformText()
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)        1    1

生成两个.tt文件但两个关联的.cs为空。

The two .tt files get generated but the two associate .cs are empty.

 

有任何建议吗?

 

 

 

 

推荐答案

您好,

您是否添加了代码生成通过右键单击模型设计图面或通过"添加新项..."来显示项目?

Did you add the code generation item by right clicking on the model design surface or via 'Add New Item...'?

听起来模板没有指向您的edmx文件。您是否可以检查模板中是否还有以下行,如果是,则需要替换名称为 

It sounds like the template isn't pointing to your edmx file. Can you check if you still have the following line in the template, if so you need to replace the 


edmxInputFile
edmxInputFile


标记你的edmx文件。如果
通过右键单击模型设计图面来添加模板,则会发生这种情况。
token with the name of your edmx file. This should happen for you if you add the template by right clicking on the model design surface.

   var inputFile = @"

   var inputFile = @"


这篇关于使用ADO.NET生成模板的问题DbContext Generator,抛出异常,.cs文件为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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