添加LINQ到SQL类打破简单的ASP.NET Web应用程序 [英] Adding Linq-to-Sql class breaks simple ASP.NET web application

查看:218
本文介绍了添加LINQ到SQL类打破简单的ASP.NET Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用应用VS2012,最新的SP /更新。

Using VS2012, latest SP/update applied.

我一直很沮丧试图让一个ObjectDataSource工作。请参见 http://bit.ly/XTpdvN 并的 http://bit.ly/XTpsHi

I have been very frustrated trying to get an ObjectDataSource to work. See http://bit.ly/XTpdvN and http://bit.ly/XTpsHi.

我开始一个新的Web应用程序项目,编译和每一步运行后,试图使步骤颗粒状越好。

I started a new Web Application project, compiling and running after each step, trying to make the steps as granular as possible.

1)创建新的空Web应用程序。结果
2)添加WebForm1.aspx的。结果
3)清洁,重建,运行(或者查看在浏览器或调试器)。结果
4)新类添加到APP_ code。结果
5)重复第3。结果
5)加入现有的.mdf的App_Data到。结果
6)重复#3。结果
7)添加的LINQ到SQL类APP_ code(Items.dbml)。把它留空。结果
8)清洁,重建,在调试器中运行:

1) Create new empty web application.
2) Add WebForm1.aspx.
3) Clean, rebuild, run (either View in Browser or in debugger).
4) Add new class to App_Code.
5) Repeat #3.
5) Add existing .mdf to App_Data.
6) Repeat #3.
7) Add Linq-to-Sql class to App_Code (Items.dbml). Leave it empty.
8) Clean, Rebuild, run in Debugger:

编译器错误信息:CS0234:类型或命名空间名称Linq的不
  在命名空间中不存在'System.Data这'(是否缺少程序集
  引用?)结果
  源错误:

Compiler Error Message: CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Source Error:

12号线:空间ODS_Restart.App_ code线13:{行14:使用
  将System.Data.Linq;第15行:使用System.Data.Linq.Mapping;第16行:
  使用System.Data这;

Line 12: namespace ODS_Restart.App_Code Line 13: { Line 14: using System.Data.Linq; Line 15: using System.Data.Linq.Mapping; Line 16: using System.Data;

据我所知,没有什么在APP_ code中的code需要LINQ的:

As far as I can tell, there is nothing in the code in App_Code that needs Linq:

namespace ODS_Restart.App_Code  
{   
    public class BAL  
    {  
        public static List<string> GetCountries()  
        {  
            return new List<string>() { "USA", "Aus", "NZ"};  
        }  
    }  
}  

正如我所说的,非常令人沮丧。如何突破这个问题的任何有识之士将不胜pctiated AP $ P $ ....

As I said, very frustrating. Any insight on how to get past this problem would be greatly apprectiated....

推荐答案

使用一个向导LINQ to SQL的程序:

use one wizard for linq to sql program:

步骤1.将新项目作为Windows窗体应用程序。
步骤2.将一个按钮和DataGridView的从它的工具箱。
步骤2.转到解决方案资源管理。添加数据库(.MDF)文件,这是我们已经采取了windows窗体应用程序项目。
第3步:通过窗口右击同样的方式形成,我们已经采取附加的LINQ to SQL类(的.dbml)文件,应用程序项目。
步骤4转至服务器资源管理器添加表数据库在步骤3中采取数据添加到该表。
第5步:打开的.dbml从Solution Explorer中拖动表格从它的服务器资源管理器中创建的文件。
第6步:打开形式,步骤2中创建该按钮,双击并添加下列code:

step 1. Take new project as windows form application . step 2. Drag one button and DataGridView from toolbox on it. step 2. Go to solution explorer. add database(.mdf) file to windows form application project which we've taken. step 3. Same way by right clicking on windows form application project which we've taken add linq to sql class(.dbml) file. step 4. Go to Server explorer add table in database taken in step 3. Add data to that table. step 5. open that .dbml file from solution explorer and drag table created from server explorer on it. step 6. Open form created in step 2. Double click on that button and add following code:

DataClasses1DataContext obj1 = new DataClasses1DataContext();
        List<pp> obj2 = obj.pps.ToList();
        dataGridView1.DataSource = obj1;

DataClasses1是在第3步第加入.dbml文件是在步骤4中OBJ1加入表名和obj2的是创建的对象。 PPS重新presents表名(PP)。

DataClasses1 is .dbml file added in step 3. pp is table name added in step 4. obj1 and obj2 are objects created. pps represents tablename(pp).

这篇关于添加LINQ到SQL类打破简单的ASP.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆