简体   繁体   中英

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:

 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:

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). I'm using the SqlServer provider

This is the answer i received on 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.). Here is the correct way to call 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). The C# compiler is more restrictive about what is allowed to be put into this anonymous type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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