我们正在用 ASP.NET/C# 开发一个项目,这不是一个非常大的项目,而是一个相当大的项目.目前我们已经开发了几个页面.我现在是从单个页面的角度说话.到目前为止,每个页面都遵循这种方法.
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 查询.插入操作完成,queries填充dropdownlists和其他database相关操作在其后面的代码中使用.
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.
虽然我们使用函数.其他页面也是如此.
We use functions though.The same goes for other pages as well.
我的问题是我应该将它们包含在 class 文件中,然后创建 objects 并调用适当的方法来完成我的工作吗?
My question is should I include them in class files and then create objects and call appropriate methods to do my stuff?
如果是,我们应该创建一个 class 还是每页创建一个类.这是否称为创建数据访问层.
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.
不要在代码隐藏中硬编码.使用类而不是每个页面一个类的问题.
Don't hard-code in the code-behind. Use Classes and it is not a matter of one class for each page.
这些链接将有所帮助:
在 LINQ to SQL 中设计数据访问层
LINQ to SQL 生成的对象可以解耦吗?
点击按钮时调用的方法代码放在哪里?
LINQ to SQL 和存储库模式
使用 C# 将业务逻辑层与用户界面层解耦
这篇关于我应该在后面的代码中直接使用 Linq To SQL 还是使用其他方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
LINQ to SQL:如何在不检索整个实体的情况下更新唯LINQ to SQL: how to update the only field without retrieving whole entity(LINQ to SQL:如何在不检索整个实体的情况下更新唯一字段)
string1 >= string2 未在 Linq to SQL 中实现,有什string1 gt;= string2 not implemented in Linq to SQL, any workaround?(string1 gt;= string2 未在 Linq to SQL 中实现,有什么解决方法吗?)
如何在条件下使用 RemoveAll 删除列表中的多个项目How to Remove multiple items in List using RemoveAll on condition?(如何在条件下使用 RemoveAll 删除列表中的多个项目?)
转换表达式树Convert Expression trees(转换表达式树)
当 IDENTITY_INSERT 设置为 OFF 时,无法为表“ClientCannot insert explicit value for identity column in table #39;ClientDetails#39; when IDENTITY_INSERT is set to OFF(当 IDENTITY_INSERT 设置为 OFF 时,
Linq 独特的 &最大限度Linq distinct amp; max(Linq 独特的 amp;最大限度)