2013-01-11 43 views
0

我創建了一個usercontrol,它應該基本上在我的表單中填充下拉列表,當頁面被加載並且在通過linq提交信息提交到數據庫後添加。linq沒有識別查詢詞條

但是我所面臨的問題是,智能感知未識別的查詢詞,如這裏和我的用戶選擇。任何指向我可能會失蹤的指針?

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Data.Entity; 
using System.Data.Linq; 
using UmbracoProd.admin.code.Test; 
using UmbracoProd.code; 

namespace UmbracoProd.usercontrols.forms 
{ 
    public partial class testCancellation : System.Web.UI.UserControl 
    { 
     private testhousingEntities canceldb = new testhousingEntities();  

     /*load form*/ 
     protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!Page.IsPostBack) 
      { 
       InitializeForm(); 
      }    

     } 
     /*updating the database with new row of info */ 
     private void CreateEntry() 
     { 
      var date = DateTime.Today; 
      var version = (from v in canceldb.CancellationVersions 
          where v.Active 
          select v).FirstOrDefault(); 

      if (version == null) 
      { 
       throw new NullReferenceException(); 
      }    

      //Try to create an entry for the database. Upon failure, sends the exception to ThrowDbError(); 
      try 
      { 
       CancellationRequest cancel = new CancellationRequest(); 

       //cancel.Semester=ddlSemester.DataTextField.ToString(); 
       cancel.SubmitDate = date; 
       cancel.StudentID = txtStudentId.ToString(); 
       cancel.FirstName = txtFirstName.ToString(); 
       cancel.MiddleName = txtMiddleName.ToString(); 
       cancel.LastName = txtLastName.ToString(); 
       cancel.AptBuilding = txtAptBuilding.ToString(); 
       cancel.AptNumber = txtAptNumber.ToString(); 
       cancel.PermAddress = txtPermAddress.ToString(); 
       cancel.PermCity = txtPermCity.ToString(); 
       cancel.PermZip = txtPermZip.ToString(); 
       cancel.PermState = ddlState.SelectedItem.ToString(); 
       cancel.Phone = txtPhone.ToString(); 
       cancel.Email = txtEmail.ToString(); 
       cancel.Reason = rbCancellation.SelectedItem.ToString(); 
       cancel.Other = txtOther.ToString(); 

       canceldb.CancellationRequests.Add(cancel); 
       canceldb.SaveChanges(); 
      } 
      catch (Exception oe) 
      { 
       ThrowDbError(oe); 
      } 
     } 

     /*database exception error*/ 
     private void ThrowDbError(Exception oe) 
     { 
      canceldb.Dispose(); 
      Session.Contents.Add("FormException", oe); 
      Response.Redirect("/DBError/", true); 
     } 

     protected void FormSubmit(object sender, EventArgs e) 
     { 
      try 
      { 
       CreateEntry(); 
      } 
      catch (Exception oe) 
      { 
       ThrowDbError(oe); 
      } 
     }  
    } 
+1

你可以給你的問題添加一些代碼嗎? –

+0

好的,對不起。我編輯了問題以包含代碼。你可以在上面查看它。再次感謝您的幫助 – Paradigm

+0

因此,intellisense問題是您的代碼中的哪個地方? –

回答

0

你只需要添加@using System.Linq到每個視圖的頂部?

+0

我其實在我的代碼中添加了這一行。 – Paradigm

+0

如果你可以發佈一些代碼,它會真的幫助 – levelnis

+0

好吧,對不起。我編輯了問題以包含代碼。你可以在上面查看它。再次感謝您的幫助 – Paradigm

0

如果它不是,你錯過了參考System.Linq的可能是你有某種對象,它是一個類型,它可以返回AsQueryable已()的。如果它可以返回,它會解決你的問題。

+0

我想你的意思是「一種可以返回'IEnumerable'的類型。」 –

+0

好的,對不起。我編輯了問題以包含代碼。你可以在上面查看它。再次感謝你的幫助 – Paradigm