0

这是我的查询,我将返回一个IEnumerable<CreditCardTransaction>进行迭代。

  public partial class CreditCardTransaction
  {

    public static IEnumerable<CreditCardTransaction> GetUnprocessedTransactions()
    {
      try
      {
        using (var context = new SuburbanEntities())
        {
          return from trans in context.CreditCardTransactions
                 where trans.IsPublished == false
                 select trans;
        }
      }
      catch (Exception ex)
      {
        Logging.Log("An error occurred.", "GetUnprocessedTransactions",Apps.ServicesConfig, ex);
        return null;
      }
    }

  }

处理完这些交易后,我将在此处修改它们:

public void ProcessFile()
{
  try
  {
    _client = new TruckServiceClient();
    _globalSetting = new GlobalSetting();

    var unprocesstransactions = CreditCardTransaction.GetUnprocessedTransactions();
    foreach (var creditCardTransaction in unprocesstransactions)
    {
      creditCardTransaction.IsPublished = ProcessTransaction(creditCardTransaction);
    }     
  }
  catch (Exception ex)
  {
    Logging.Log("An error occurred.", "ProcessCreditCardTransactions.ProcessFile", Apps.RemoteServices, ex);
  }
}

我在这里修改交易:

creditCardTransaction.IsPublished = ProcessTransaction(creditCardTransaction);

但是一旦我保存了它们,我可以直接更新实体还是需要创建另一个方法来传递这些信息?

4

1 回答 1

1

您无权访问上下文的问题。这里有一些示例: https ://github.com/geersch/EntityFrameworkObjectContext

如果您正在开发 Asp.Net 应用程序,您将在本文中说明一些缺点: http ://dotnetslackers.com/articles/ado_net/Managing-Entity-Framework-ObjectContext-lifespan-and-scope-in​​-n -layered-ASP-NET-applications.aspx#managing-objectcontext-instantiation

于 2013-02-25T01:31:30.443 回答