返回 ObjectQuery使用反射从 objectQuery
我有一种方法,该方法在此 ObjectQuery 对象中返回 ObjectQuery 的对象,对象的类型是 ObjectQuery,现在我想在此对象中包含表 使用反射,我调用了方法“包括使用反射”,但我收到错误,有人可以告诉我错误吗?这是示例代码。
ObjectQuery objTest = LoadEntitiy(entites,entityClassType);
public ObjectQuery LoadEntitiy(ClientEntities entities, Type entityClasstype)
{
PropertyInfo pi = entities.GetType().GetProperties().First(item => item.Name == entityClasstype.Name.ToString());
Object obj = pi.GetValue(entities, null);
Type objContext = obj.GetType();
return (ObjectQuery)obj;
}
现在我调用使用此处的反射包含它的方法
Type lstType = typeof(ObjectQuery<>);
Type constructedType = lstType.MakeGenericType(typeof(ObjectQuery<>));
MethodInfo addListItemMethod = constructedType.GetMethod("Include");
addListItemMethod.Invoke(objTest, new object[] {"tablename" });
I have one method which is returning the object of ObjectQuery in this ObjectQuery object the type of object is ObjectQuery, now i want to include table in this object
using reflection, i called the method Include using reflection for this but i m getting the error can someone please tell me the error. here is the sample code.
ObjectQuery objTest = LoadEntitiy(entites,entityClassType);
public ObjectQuery LoadEntitiy(ClientEntities entities, Type entityClasstype)
{
PropertyInfo pi = entities.GetType().GetProperties().First(item => item.Name == entityClasstype.Name.ToString());
Object obj = pi.GetValue(entities, null);
Type objContext = obj.GetType();
return (ObjectQuery)obj;
}
now i m calling the method for including it using the reflection that is here
Type lstType = typeof(ObjectQuery<>);
Type constructedType = lstType.MakeGenericType(typeof(ObjectQuery<>));
MethodInfo addListItemMethod = constructedType.GetMethod("Include");
addListItemMethod.Invoke(objTest, new object[] {"tablename" });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您似乎想定义一个约定来始终“包含”一组特定的数据。
这种约定通常称为急切加载,并且还有诸如延迟加载之类的替代方案。
EF 4.1 或更高版本已包含为您执行此操作的功能,请参阅 http://msdn.microsoft.com/en-us/library/gg715120(v=vs.103).aspx
It seems that you want to define a convention to always "Include" a certain set of data.
This convention is normally known as eager loading and there are alternatives like lazy loading.
EF 4.1 or greater already includes functionality to do this for you, see http://msdn.microsoft.com/en-us/library/gg715120(v=vs.103).aspx
现在 objtest 包含您想要包含的所有表名称。
Now the objtest contains the all the table names which you want to include.