1

使用しています。ASP.NET Web Forms/C#ページがあります。クエリを使用して関連するすべてのタスクを実行する予定のクラスをCustomer.aspx作成しました。CustomerBLLLinq To SQLdatabase

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 、良い習慣であると考えられていますか?

私が正しい方向に向かっているかどうか誰かに教えてもらえますか?

どんな提案でも大歓迎です。

4

2 に答える 2

1

関数を呼び出す方法は問題ありません。ただし、CustomerBLL.cs内でnullをチェックする必要があります。

于 2012-07-03T06:46:56.130 に答える