使用しています。ASP.NET Web Forms/C#
ページがあります。クエリを使用して関連するすべてのタスクを実行する予定のクラスをCustomer.aspx
作成しました。CustomerBLL
Linq To SQL
database
GetDateFormat()
この例を考えてみましょう。これが私のCustomerBLL
クラスで呼び出されたメソッドで、日付形式をから返しdatabase
ます。コードは次のとおりです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
namespace CwizBankApp
{
public class CustomerBLL
{
public string GetDateFormat()
{
using (var db = new DataClasses1DataContext())
{
var format = db.CODEs.Where(code => code.NAME.Equals("dateformat")).SingleOrDefault();
return format.DRNAME;
}
}
}
}
code behind
私はこのような別の関数の中でこの関数を呼び出しています。
public void RetrieveDateFormat()
{
//In this function we retrieve the date format
//from the database to identify if it is british or american
var format = CustomerBLL.GetDateFormat();
//The global variable gDateFormat stores the format
if (format != null)
{
Global.DateFormat = format;
}
CustomerBLL.cs
関数を呼び出して結果を最初に保存してから、nullかどうかを確認しています。このようにする必要がありますか、それともファイル自体にnullかどうかを確認する必要がありますか?
これを行うためのより良い方法は何ですか。関数を呼び出す私の方法はGetDateFormat()
実行可能です。
Linq
また、そのようなクラスファイルでクエリを維持し、それらをから呼び出すというこのアプローチはcode behind
、良い習慣であると考えられていますか?
私が正しい方向に向かっているかどうか誰かに教えてもらえますか?
どんな提案でも大歓迎です。