EF Core 1.1迁移 - 目前的CSharpHelper不能支持类型的文字 [英] EF Core 1.1 Migration - The current CSharpHelper cannot scaffold literals of type

查看:1253
本文介绍了EF Core 1.1迁移 - 目前的CSharpHelper不能支持类型的文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一个非常晦涩的错误,我甚至不知道从哪里开始...


当前CSharpHelper不能支持文本类型
'System.Func`3 [Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator]的文字。
配置您的服务以使用可以的。


这是在我运行


时发生的

  dotnet ef migrations添加初始

更新1 - 基于Rob的问题



应用程序的体系结构使用丰富的域模型,因此有几个解决方法可以获取像封装的集合和Jimmy Bogard的类型枚举模式一样工作。



每个域模型对象都有它自己的 EntityTypeBuilder 类在数据访问层中,所有这些都从 DbContext 中的 OnModelCreating 中调用。这些还会向控制台输出一些信息,所以我可以看到构建器没有导致任何错误(目前没有任何错误)。



DbContext 仅向聚合根实体公开 DbSet ,或者将它另一种方式,只有具有相应的存储库类的实体。域模型对象的其余部分是导航属性,因此不需要通过 DbContext 公开 DbSet



平台细节(据我所知)




  • .NET Core 1.1(Runtime + SDK)

  • EF Core 1.1

  • Microsoft.EntityFrameworkCore.Tools 1.0.0-preview2-final

  • Microsoft.EntityFrameworkCore.Design 1.0.0-preview2-final


解决方案

您正在使用.NET Core 1.1运行时,但是使用旧的工具包(您应该使用最新的工具,直到此日期为 preview4 ,仍然是 alpha ,相反的运行时 - 是的,不是很直观起初)



总之,这是一个


This seems to be a really obscure error, and I don't even know where to start with it...

The current CSharpHelper cannot scaffold literals of type 'System.Func`3[Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator]'. Configure your services to use one that can.

This is occurring when I run

dotnet ef migrations add initial

Update 1 - based on Rob's question

The architecture of the application uses a rich domain model, so there are a few "workarounds" to get things like encapsulated collections, and Jimmy Bogard's typed enumeration pattern working.

Each domain model object has it's own EntityTypeBuilder class in the data access layer, all of which are called from OnModelCreating in the DbContext. These also output some information to the Console, so I can see that the builder isn't causing any errors (none of them are at this point).

The DbContext only exposes DbSet for aggregate root entities, or to put it another way, only entities that have a corresponding repository class. The rest of the domain model objects are navigation properties, and therefore do not require DbSet to be exposed via the DbContext.

Platform specifics (as far as I'm aware)

  • .NET Core 1.1 (Runtime + SDK)
  • EF Core 1.1
  • Microsoft.EntityFrameworkCore.Tools 1.0.0-preview2-final
  • Microsoft.EntityFrameworkCore.Design 1.0.0-preview2-final

解决方案

You are using a .NET Core 1.1 runtime but the old tooling packages (you should be using the latest tooling, as of this date it is preview4, which is still in alpha, contrary to the runtime - yeah, not very intuitive at first)

In summary, this is a Known Issue

"tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4"
}

  • You may, or may not need to fix the SDK version by using a global.json just above the src folder which should contain your code as explained in Hanselman's blog

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

EDIT: Just to give you a more complete answer, this is how my project.json and my sample project looks like (all done in VS Code):

{
  "version": "1.0.0-*",
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.EntityFrameworkCore": "1.1.0-preview1-final",
    "Microsoft.EntityFrameworkCore.Design": "1.1.0-preview1-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview1-final",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0-preview1-final",
  },
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
  }
}

这篇关于EF Core 1.1迁移 - 目前的CSharpHelper不能支持类型的文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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