我应该直接在代码中使用Linq To SQL还是使用其他方法?

时间:2022-06-27 15:11:14

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.

我们正在ASP.NET / C#中开发一个项目,这个项目不是一个非常大的项目,而是一个相当大的项目。目前我们开发了几页。我现在正在谈论单页的观点。到目前为止,每个页面都遵循这种方法。

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.

在我的页面背后的代码中,我们直接使用Linq To SQL查询。插入操作完成,填充下拉列表的查询和其他数据库相关的操作在自身后面的代码中使用。

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.

这种方法是一种很好的编程习惯吗?

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.

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

1 个解决方案

#1


7  

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

不要在代码隐藏中硬编码。使用类,每个页面不是一个类的问题。

These links will help:

这些链接将有助于:

Designing A Data Access Layer in LINQ to SQL

在LINQ to SQL中设计数据访问层

Can LINQ to SQL generated objects be decoupled?

LINQ to SQL生成的对象可以解耦吗?

Where to put method code which is called on click of a button?

在点击按钮时调用方法代码的位置?

LINQ to SQL and the repository pattern

LINQ to SQL和存储库模式

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

使用C#将业务逻辑层与用户界面层分离

#1


7  

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

不要在代码隐藏中硬编码。使用类,每个页面不是一个类的问题。

These links will help:

这些链接将有助于:

Designing A Data Access Layer in LINQ to SQL

在LINQ to SQL中设计数据访问层

Can LINQ to SQL generated objects be decoupled?

LINQ to SQL生成的对象可以解耦吗?

Where to put method code which is called on click of a button?

在点击按钮时调用方法代码的位置?

LINQ to SQL and the repository pattern

LINQ to SQL和存储库模式

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

使用C#将业务逻辑层与用户界面层分离