簡體   English   中英

找不到DataClassesDataContext-VS2012

[英]DataClassesDataContext Not Found - VS2012

我正在ASP.NET中做一個項目,並且正在將Visual Studio 2012與.NET 4.5一起使用。 我一直在網上搜索我的問題,但尚未找到任何解決方案。 也許這里有人可以幫助我。

我正在一個項目上,並從一個空的Web應用程序開始。 我添加了一個文件夾“ App_Code”,其中放入了我的模型和數據類。 我添加了具有正確表的LINQ-to-SQL類,並將此文件保存在App_Code文件夾中。

現在,當我將一個類添加到App_Code文件夾時,該類找不到DataClasses。

這是文件夾App_Code中我的類“ Product”的代碼:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Outside.App_Code
{
    public partial class Product
    {
        private static OutsideDataClassesDataContext db;

        public static List<Product> GetAll(int id)
        {
            // Init the DB
            db = new OutsideDataClassesDataContext();
            // Get all the products and return
            return db.Products.Where(a => a.id > 0).ToList();
        }
    }
}

Visual Studio不允許我運行代碼。 我收到此錯誤:

The type or namespace name 'OutsideDataClassesDataContext' could not be found (are you missing a using directive or an assembly reference?) \App_Code\Product.cs    10  24  Outside

Product.cs文件的生成操作為“編譯”。

有人可以幫忙嗎? 還是嘗試幫助識別數據類? 我仍在學習ASP.NET。 如果您需要其他數據或其他代碼,請告訴我。

提前致謝!

我已經從文件夾App_Code中刪除了所有內容,並創建了一個名為Models的新文件夾。 將所有內容(Product類和新的OutsideDataClass類)放置在Models文件夾中,然后突然起作用。 奇怪的。

App_Code似乎是個壞主意。

首先,請確保已從Visual Studio安裝程序手動添加了Linq to SQL。 它將在“單個組件”下

錯誤正在尋找使您連接到的數據庫具有通用版本的Linq dbml文件,然后在解決方案/項目上單擊鼠標右鍵以添加該dbml。

選擇添加新項,然后在數據下,選擇Linq-To-SQL類。 這將創建一個空的DBML文件。 然后,您需要創建與數據庫的服務器連接(如果尚未建立),並將所需的表拖到DBML設計器中。

看起來您的OutsideDataClassesDataContext()位於解決方案的另一個名稱空間或另一個項目中。

嘗試將名稱空間名稱縮短為Outside或從類所在的項目中添加引用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM