如何解决此错误“无法将lambda表达式转换为类型'string',因为它不是委托类型”

时间:2015-04-19 23:06:40

标签: c# linq lambda

我试试这个代码并且它给了我关于'其中' 我验证:using system.linq;using System.Data.Entity但未修复(我使用visual studio 2012 ultimate和sql server 2008 r2)

代码:

public static int updatecondidate(int condidateID, condidate_table   updatedcondidateData)
{ int rowAffected = 0;

    using (EmployeementSystemEntities DB = new EmployeementSystemEntities())
    {
        //select condidate for update
        condidate_table condidateforupdate = (from anything in DB.condidate_table
                                              where anything.condidate_id == condidateID
                                              select anything).FirstOrDefault();
        condidateforupdate.condidate_name = updatedcondidateData.condidate_name;
        condidateforupdate.condidate_phone = updatedcondidateData.condidate_phone;
        condidateforupdate.condidate_email = updatedcondidateData.condidate_email;
        condidateforupdate.condidate_pic = updatedcondidateData.condidate_pic;
        rowAffected = DB.SaveChanges();
    }
    return rowAffected;
}

同样的错误在"选择"
 //选择所有condidate

public static List<condidate_table> SelectAllCondidate()
{
    using (EmployeementSystemEntities DB = new EmployeementSystemEntities())
    {
        List<condidate_table> AllCondidate = (from anything in DB.condidate_table 
                                              select anything).ToList<condidate_table>();
        return AllCondidate;
    }
}

2 个答案:

答案 0 :(得分:0)

   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
    callbackManager = CallbackManager.Factory.create();
    setContentView(R.layout.activity_main);
    name = (TextView) findViewById(R.id.name);
    mywebView = (WebView) findViewById(R.id.webView);
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            name.setText(
                    "User ID: "
                            + loginResult.getAccessToken().getUserId()
                            + "\n" +
                            "Auth Token: "
                            + loginResult.getAccessToken().getToken()
            );


            WebView ourBrow;
            ourBrow = (WebView) findViewById(R.id.webView);
            // cancel the web intent that default in android setting
            ourBrow.setWebViewClient(new myWebViewClient());
            String url = "https://m.facebook.com/groups/819387484767105";

            // webView settings
            ourBrow.getSettings().setJavaScriptEnabled(true);
            ourBrow.getSettings().setLoadWithOverviewMode(true);
            ourBrow.getSettings().setUseWideViewPort(true);
            ourBrow.getSettings().setDomStorageEnabled(true);
            ourBrow.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
            ourBrow.getSettings().setUserAgentString("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0");
            ourBrow.loadUrl(url);
        }

在我的情况下,我错过了这个:

public List<ISSUES> ListIssues()
{
    List<ISSUES> list = new List<ISSUES>();
    using (FTUEntities1 db = new FTUEntities1())
    {
        list = db.ISSUES.Include(a => a.CLIENTS).ToList();
        return list;
    }
}

答案 1 :(得分:-1)

where anything.condidate_id = condidateID应为where anything.condidate_id == condidateID(注意双等号)。

以下是我可以找到的问题的一般列表,人们报告已经为他们造成了同样的错误。我会在发现更多时更新它。

查询语法

  • 在where子句
  • 中使用=代替==
  • 在查询语句中引用尚未声明的变量
  • 对变量名称使用不正确的标点符号(转到第二点)
  • 在查询中调用方法并忘记括号,例如c.FullNameReverse代替c.FullNameReverse()
  • 在创建复合谓词时在where子句中缺少条件运算符(&&||等...)
  • 引用静态属性,就像它们是实例属性一样
  • 引用不存在的对象属性

缺少使用语句

  • using System.Linq
  • using System.Data.Entity