linq没有识别查询字词

时间:2013-01-11 20:13:01

标签: c# .net linq razor visual-studio-2012

我创建了一个usercontrol,它应该在加载页面时基本上填充表单中的下拉列表,并在提交后通过linq将信息提交到数据库中。

然而,我面临的问题是intellisense没有识别查询术语,例如我的usercontrol中的where和select。有什么指向我可能缺少的东西吗?

    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);
            }
        }      
    }

2 个答案:

答案 0 :(得分:0)

您只需要在每个视图的顶部添加@using System.Linq吗?

答案 1 :(得分:0)

如果不是你缺少对System.Linq的引用,那么你可能有某种类型的对象可以返回AsQueryable()。如果它可以返回,它将解决您的问题。