我应该使用LINQ直接在code SQL后面或使用一些其他的方法呢? [英] Should I use Linq To SQL directly in code behind or use some other approach?

查看:146
本文介绍了我应该使用LINQ直接在code SQL后面或使用一些其他的方法呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发项目ASP.NET/C#这是不是一个很大的项目,而是一个相当大的。目前我们已经开发了几页。我从一个单一页面右侧now.The的做法是遵循已发展至今每一页的角度来讨论。

We are developing a project in ASP.NET/C# which is a not a very large project but a sizeable one. Currently we have developed few pages. I am talking from point of view of a single page right now.The approach is followed for every pages that has been developed so far.

在我的页面中,我们直接使用 LINQ to SQL的查询背后的code。在插入操作完成后,查询填写 dropdownlists 和其他数据库相关操作都在背后本身code使用。

In the code behind of my page we use Linq To SQL queries directly. The insert operation is done , queries to fill dropdownlists and other database related operations are used in code behind itself.

我们使用的功能though.The同样适用于其他网页也是如此。

We use functions though.The same goes for other pages as well.

我的问题是我应该包括他们在文件,然后创建对象并调用适当的方法来尽我的东东?

My question is should I include them in class files and then create objects and call appropriate methods to do my stuff?

如果是,我们应该建立一个单一的或每页创建一个类。这是所谓的创建数据访问层

If yes, should we create a single class or create one class per page. Is this called creating Data Access Layer.

谁能帮我提出一个适当的方式做到这一点?

Can anyone help me suggest a proper way to do this?

这是一个好的方法编程习惯。

Is this approach a good programming practice.

这是我们正在使用我们的code后面

This is a simple function that we are using in our code behind

public void AccountTypeFill()
        {
            //Get the types of Account ie Entity and individual
            var acc = from type in dt.mem_types
                       select type.CustCategory;
            if (acc != null)
            {
                NewCustomerddlAccountType.DataSource = acc.Distinct().ToList();
                NewCustomerddlAccountType.DataBind();  
            }
        }

任何人都可以指向一个简单的例子,指的是这个查询?

Can anyone point a simple example referring to this query?

我希望我的问题是有道理的。
任何建议都欢迎。

I hope my question makes sense. Any suggestions are welcome.

推荐答案

不要在code-背后不硬code。使用类和它不是为​​每一页一个类的问题。

Don't hard-code in the code-behind. Use Classes and it is not a matter of one class for each page.

这些链接将帮助:

<一个href=\"http://www.simple-talk.com/dotnet/.net-framework/designing-a-data-access-layer-in-linq-to-sql/\">Designing在LINQ数据访问层到SQL

能的LINQ to SQL生成的对象脱钩?

<一个href=\"http://forums.asp.net/t/1817339.aspx/1?Where%20to%20put%20method%20$c$c%20which%20is%20called%20on%20click%20of%20a%20button%20\">Where把方法code这就是所谓的一个按钮的点击?

LINQ to SQL和

<一个href=\"http://aspalliance.com/1360_Decoupling_Business_Logic_Layer_from_the_User_Interface_Layer_using_C.all\">Decoupling使用C#从用户界面层业务逻辑层

Decoupling Business Logic Layer from the User Interface Layer using C#

这篇关于我应该使用LINQ直接在code SQL后面或使用一些其他的方法呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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