错误:表达式树不能包含动态操作 [英] Error: An expression tree may not contain a dynamic operation

查看:2619
本文介绍了错误:表达式树不能包含动态操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Asp.Net 4和C#中,我使用EF 4

I use Asp.Net 4 and C#, I use EF 4.

我有这个疑问,我收到一个错误:

I have this query, I receive an error:

 An expression tree may not contain a dynamic operation







dynamic o = e.Item.DataItem;
var imagesContent = context.CmsImagesContents.FirstOrDefault(img => img.ContentId == o.ContentId);



这似乎是IMPOSIBLE到投用兰巴表达一个动态类型。

It seems is imposible to Cast a Dynamic Type using a Lamba Expression.

我怎样才能解决这个问题,并能够在我兰巴使用我的对象 0?谢谢

How I can fix the problem, and able to use my object o in my Lamba? Thanks

PS:
e.Item.DataItem 是类型 CmsContent的
o.ContentId 的类型为内部

PS: e.Item.DataItem is of Type CmsContent and o.ContentId is of type Int

推荐答案

我发现了一个解决我的问题。

I found out a solution to my problem.

     int contentId = (int)o.ContentId;
     var image = context.CmsImagesContents.FirstOrDefault(img => img.ContentId == contentId);

这篇关于错误:表达式树不能包含动态操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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