2012-03-12 12 views
0

次のコードでエラーが発生します。ソリューション名前 'AppDate'は現在のコンテキストに存在しません

using (var context = new CatLiveDataContext()) 
      { 
       DateTime AppDate; 
       var fieldsaleId = context.FieldSales.Where(fs => fs.CompanyId == companyId && fs.IsClosed).Select(fs =>(int?) fs.Id).SingleOrDefault(); 
       if (fieldsaleId != null) 
       { 
       var fieldsale = context.FieldSales.Where(fs => fs.Id == fieldsaleId).SingleOrDefault(); 
       var calenderitem = fieldsale.CalendarItem; 

        if (calenderitem != null) 
        { 
         AppDate = calenderitem.StartTime; 
        } 
        else 
        { 
         AppDate = DateTime.Today; 
        } 
       } 
      } 

      using (var repository = new TaskRepository()) 
      { 
       repository.CreateDesiredDirectoryTask(companyId, directoryName, directoryEdition, directoryHeading, userStaffId, AppDate); 
       repository.SubmitChanges(); 
      } 

エラー見つけるように見えるカント:名「AppDate」は現在のコンテキストで

存在しない、私はLINQクエリからIメソッドにappdateを渡すとき、私はエラーを取得しています。

答えて

0

最初のusingステートメント内にAppDateと宣言しました。そのため、最初のステートメントの範囲外です。宣言をそのステートメントの前に移動するか、最初のusingステートメントの全体を分かりやすくするため別の方法に入れてください:

// Rename according to real meaning 
DateTime appDate = FetchAppDate(companyId, fieldsaleId); 
using (var repository = new TaskRepository()) 
{ 
    repository.CreateDesiredDirectoryTask(companyId, directoryName, 
     directoryEdition, directoryHeading, userStaffId, AppDate); 
    repository.SubmitChanges(); 
} 
関連する問題