0

基本的に、ページが読み込まれたときにフォームにドロップダウンリストを入力し、送信後にlinqを介してデータベースに情報を送信するユーザーコントロールを作成しました。

ただし、私が直面している問題は、インテリセンスがユーザーコントロールの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);
            }
        }      
    }
4

2 に答える 2

0

@using System.Linq各ビューの上部に追加するだけですか?

于 2013-01-11T20:16:19.633 に答える
0

System.Linq への参照が欠落しているわけではない場合は、AsQueryable() を返すことができるタイプのオブジェクトがある可能性があります。それを返すことができれば、問題は解決します。

于 2013-01-11T20:32:08.350 に答える