我怎样才能给出个人资料价值 [英] How Can I Give Profile Value

查看:69
本文介绍了我怎样才能给出个人资料价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


如何在GridView中显示用户配置文件值

我写了这段代码但是它给出了错误

我的代码:

hi
How do I display a user profile values ​​into a GridView
I have written this code but it gives error
my code:

using (DBNezamEntities db = new DBNezamEntities())
            {
                var Query = from ro in db.Users.Include("Profiles")
                            select new
                            {
                                UserName = ro.UserName,
                                Name = Profile.GetProfile(ro.UserName.ToString()).Family


                            };
                GridView2.DataSource = Query;
                GridView2.DataBind();

            }





错误:



error:

LINQ to Entities does not recognize the method 'ProfileCommon GetProfile(System.String)' method, and this method cannot be translated into a store expression.

推荐答案

所以你的问题是你不明白错误信息? - 我会说非常明确。



想想发生了什么:LinqToEntity尝试执行给定的表达式树。所以LinqToEnitiy是评估你的表达的特定提供者。它应该如何知道你的(静态?)GetProfile函数?



所以你必须改变方法来获取查询中的配置文件。在我的理解中,用户应该有一个Navigation属性来链接它的配置文件(你在查询中包含配置文件,不是吗?)



但这是一般的LINQ问题:你可以构造一个表达式树 - 可编译所有好的。但是在评估时(通过LinqToObjects,LinqToXml等特定的LINQ提供程序),提供程序无法知道代码中的函数...
So your Problem is you don't understand the error message? - wich is quite explicit I'd say.

Think about what is happening: LinqToEntity tries to execute the given expression tree. So LinqToEnitiy is a specific provider for evaluating your expression. How should it know about your (static?) GetProfile function?

So you have to change the approach to get the profiles inside the query. In my understanding there should be a Navigation property on a user to link it with it's profile (you are including the Profiles in the query, no?)

But this is a general LINQ "Problem": You can construct an Expression tree - compilable all good. But when evaluated (by a specific LINQ provider such as LinqToObjects, LinqToXml, ..) the provider can't know about functions in your code...


避免这种情况的一种方法是从Query中移除Profile.GetProfile(ro.UserName.ToString())。Family并将其存储在临时变量中并使用查询中的变量。
One way to avoid this is to remove the Profile.GetProfile(ro.UserName.ToString()).Family from Query and store it in a temp variable and use the variable in the query.


这篇关于我怎样才能给出个人资料价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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