简体   繁体   English

EF RenameColumn参数randomArguments不支持c#中的lambda,但在VB.Net中支持(无法将lambda表达式转换为类型object)

[英]EF RenameColumn parameter anonymousArguments has no support for lambda in c# but does in VB.Net ( cannot convert lambda expression to type object)

In VB.Net i can adjust my migration ( which does an AddColumn and DropColumn when renaming properties) like this: 在VB.Net中,我可以调整迁移(重命名属性时执行AddColumn和DropColumn),如下所示:

 RenameColumn("dbo.InvoiceLines", "Invoice_InvoiceID", "OrderId", Function(d) d.Int(nullable:=False))

In c#, when i adjust my method ( instead of AddColumn and DropColumn) i try to use the following: 在C#中,当我调整方法(而不是AddColumn和DropColumn)时,我尝试使用以下方法:

RenameColumn("dbo.InvoiceLines", "Invoice_InvoiceID", "OrderId",  c => c.Int(nullable: false));

But it gives me the following error: 但这给了我以下错误:

Cannot convert lambda expression to type object because it is not a delegate type

Any idea how to fix this? 任何想法如何解决这个问题? It looks like it's unsupported in C# ( not sure). 看起来C#不支持它(不确定)。 I'm using the SqlServer provider 我正在使用SqlServer提供程序

This is the answer i received on codeplex: https://entityframework.codeplex.com/workitem/2882 这是我在Codeplex上收到的答案: https ://entityframework.codeplex.com/workitem/2882

-- From Rowan -来自罗文

The RenameColumn method does not take a function to specify the type of the column (since it just renames and doesn't change the data type etc.). RenameColumn方法不具有指定列类型的函数(因为它仅重命名并且不更改数据类型等)。 Here is the correct way to call RenameColumn. 这是调用RenameColumn的正确方法。

BTW the reason this compiles on VB.NET is that the compiler is stashing your function in the optional anonymousArguments parameter that all our migrations APIs take (used for customizing the migrations pipeline). 顺便说一句,它在VB.NET上进行编译的原因是,编译器将函数存储在我们所有迁移API都采用的(用于自定义迁移管道的)可选的randomArguments参数中。 The C# compiler is more restrictive about what is allowed to be put into this anonymous type. C#编译器对允许放入此匿名类型的内容有更多限制。

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

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