【问题标题】:Exception in Entity Framework: Error 0194: All artifacts loaded实体框架中的异常:错误 0194:已加载所有工件
【发布时间】:2017-03-05 14:56:14
【问题描述】:

这是一个 c#/asp.net 项目。我得到的完整错误消息是:错误 0194:加载到项目集合中的所有工件必须具有相同的版本。遇到了多个版本。

这个项目从 3.5 开始并升级到 4.0。当我尝试测试任何方法时,我收到了我在主题行中发布的错误。我将包括它引发异常的实际行。如果人们需要查看任何内容以尝试帮助让我知道,我也会发布它。任何帮助将不胜感激,我没有运气。

/// <summary>
/// Initializes a new SFBExternalPaymentsEntities object using the connection string found in the 'SFBExternalPaymentsEntities' section of the application configuration file.
/// </summary>    
public SFBExternalPaymentsEntities() : base("name=SFBExternalPaymentsEntities", "SFBExternalPaymentsEntities")     
{
    this.ContextOptions.LazyLoadingEnabled = false;     
    OnContextCreated();    
}

/// <summary>    
/// Initialize a new SFBExternalPaymentsEntities object.
/// </summary>
public SFBExternalPaymentsEntities(string connectionString) : base(connectionString, "SFBExternalPaymentsEntities")     
{
    this.ContextOptions.LazyLoadingEnabled = false;    
    OnContextCreated();    
}

/// <summary>
/// Initialize a new SFBExternalPaymentsEntities object.
/// </summary>
public SFBExternalPaymentsEntities(EntityConnection connection) : base(connection, "SFBExternalPaymentsEntities")     
{
    this.ContextOptions.LazyLoadingEnabled = false;     
    OnContextCreated();    
}
#endregion

添加了调用构造函数的方法。

public static CreditCardResponse AuthCapture(CreditCard newCC)
{
    ACHResponse validateResponse = CreditCard.Validate(newCC);
    if (validateResponse.Status == "Accepted")
    {
        Profile currentProfile = new Profile();
        currentProfile = ProfilesGateWay.GetByID(newCC.ProfileID);
        CreditCardTransaction newCCTransaction = CreateCreditCardTransaction(newCC, currentProfile);
        ServiceClient client = new ServiceClient();
        CreditCardTransactionResponse cctResponse = client.CreditCardAuthorizeAndCapture(newCCTransaction);
        client.Close();
        CreditCardResponse ccResponse = CreateCCResponse(cctResponse);

        if (ccResponse.ResponseCode == 1)
        {
            int authAVS = ConvertAVStoInt(ccResponse.AVSResponse);
            int appAVS = ConvertAVStoInt(newCC.AVLevel);
            bool isAVSPass = CompareAVS(authAVS, appAVS);

            if (isAVSPass == false)
            {
                ccResponse.ResponseCode = 0;
                ccResponse.ResponseReasonCode = 99;
                ccResponse.ResponseText = "Did not meet your AVS requirements";
                return ccResponse;
            }
                else
                {

                 int newCCID =  CreateCreditCardRecord(newCC, currentProfile, cctResponse, "Captured", "Auth_Capture");
                CreditCardRecord updateCC = CreditCardRecordsGateWay.GetByID(newCCID);
                updateCC.CaptureOn = DateTime.Now;
                CreditCardRecordsGateWay.Update(updateCC);
                return ccResponse;
                }
            }
        else
        {
            return ccResponse;
        }

     }
    CreditCardResponse newCCResponse = new CreditCardResponse();
    newCCResponse.ResponseCode = 0;
    newCCResponse.AchResponse = validateResponse;
   return newCCResponse;
}
public static CreditCardResponse PriorAuthCapture(CreditCard newCC)
{
    CreditCardRecord ccRecord = CreditCardRecordsGateWay.GetByCCGateWayID(newCC.CreditCardTransactionID);
    ServiceClient client = new ServiceClient();
    CreditCardTransaction ccTransaction = client.CreditCardGetTransactionById(ccRecord.CCGatewayID);
    CreditCardTransactionResponse cctResponse = client.CreditCardPriorAuthorizationCapture(ccTransaction);
    if (cctResponse.ResponseCode == 1)
    {
        ccRecord.Status = "Captured";
        ccRecord.CaptureOn = DateTime.Now;
    }

    CreditCardResponse ccResponse = CreateCCResponse(cctResponse);
    return ccResponse;
}
protected static int CreateCreditCardRecord(CreditCard newCC, Profile currentProfile, CreditCardTransactionResponse cctResponse, string status, string transactionType)
{
    CreditCardRecord newCCRecord = new CreditCardRecord();
    newCCRecord.Address = newCC.Address;
    newCCRecord.AddressVerificationLevel = newCC.AVLevel;
    newCCRecord.Amount = newCC.Amount;
    newCCRecord.CardCode = newCC.CardCode;
    newCCRecord.CardNumber = newCC.CardNumber;
    newCCRecord.CCGatewayID = cctResponse.CreditCardTransactionID;
    newCCRecord.City = newCC.City;
    newCCRecord.CompanyName = newCC.CompanyName;
    newCCRecord.CreateBy = currentProfile.ACHCompanyName;
    newCCRecord.CreateOn = DateTime.Now;
    newCCRecord.Description = newCC.Description;
    newCCRecord.Expiration = newCC.Expiration;
    newCCRecord.FirstName = newCC.FirstName;
    newCCRecord.LastName = newCC.LastName;
    newCCRecord.Profile.ProfileID = currentProfile.ProfileID;
    newCCRecord.State = newCC.State;
    newCCRecord.Status = status;
    newCCRecord.TransactionType = transactionType;
    newCCRecord.Zip = newCC.Zip;
    return CreditCardRecordsGateWay.Insert(newCCRecord);
}

【问题讨论】:

    标签: .net-4.0 c#-4.0 entity-framework-4


    【解决方案1】:

    您刚刚将构造函数发布到您的 SFBExternalPaymentsEntities 类,但您似乎说当您调用返回实体集合的方法时遇到异常,这会使用您收到的异常消息发送。问题可能出在您正在调用的方法中,或者在调用它的代码中,而不是在您发布的构造函数代码中。您能否发布一些更相关的代码或解释您发布的代码与异常的关系。

    【讨论】:

    • 本,感谢您的回复。我尝试了几种方法,它们都给出了相同的错误,但我会发布其中一种方法,以防我走错了路。我正在为下一条评论添加一些代码。这里太长了。
    • >public static CreditCardResponse AuthCapture(CreditCard newCC) { ACHResponse validateResponse = CreditCard.Validate(newCC); if (validateResponse.Status == "Accepted") { Profile currentProfile = new Profile(); currentProfile = ProfilesGateWay.GetByID(newCC.ProfileID); CreditCardTransaction newCCTransaction = CreateCreditCardTransaction(newCC, currentProfile);最后一行是它碰到构造函数并死亡的地方。
    • 本,我只是将方法添加到原始帖子中。不好意思,第一次发帖,不熟悉界面。感谢收看。
    【解决方案2】:

    当我将我的一个项目从 .net 4.0 更新到 4.5 时,我遇到了同样的问题,原因可能是目标项目中引用了另一个项目中的另一个 .edmx 文件。 问题解决方案:将引用并包含 .edmx 文件的另一个项目更新为 .net 4.5,然后右键单击这两个项目中的每个 .edmx 文件,然后选择“运行自定义工具” 它对我有用,希望它对阅读本文的每个人都有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-30
      相关资源
      最近更新 更多