0

次の例外を受け取りました: 例外の詳細: System.InvalidOperationException: メソッド自体または含まれている型が完全にインスタンス化されていないため、メソッドを実行できませんでした。

どんな助けでも大歓迎です。

スタックトレース:

行 98: SqlParameter userID = new SqlParameter("@UserProfileID", user.ID);

行 99: SqlParameter Title = new SqlParameter("@Title", user.FirstName + "Inventory");

行 100: ケース case1 = Context.Database.SqlQuery("spCasesAdd @UserProfileID, @Title", userID, Title).FirstOrDefault();

行 101: tranScope.Complete();

102行目: }

ソース ファイル: c:\Development\UI\ViewModels\NewAgencyViewModel.cs 行: 100

System.Data.Entity.Internal.InternalContext.GetStateEntries() +0 System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() +102 System.Data.Entity.Internal.InternalSqlQuery 1.GetEnumerator() +41 System.Linq.Enumerable.FirstOrDefault(IEnumerable1 ソース) +152

クラスのコード:

  public class NewAgencyViewModel
  {
    [Required]
    [StringLength(150, MinimumLength = 6)]
    [Display(Name = "Agency Name:")]
    public string AgencyName { get; set; }

    [Required]
    [StringLength(50, MinimumLength = 2)]
    [Display(Name = "Contact First Name:")]
    public string FirstName { get; set; }

    [Display(Name = "Contact Middle Name:")]
    [StringLength(50, MinimumLength = 2)]
    public string MiddleName { get; set; }

    [Required]
    [Display(Name = "Contact Last Name:")]
    [StringLength(50, MinimumLength = 2)]
    public string LastName { get; set; }

    [Required]
    [DataType(DataType.EmailAddress)]
    [Display(Name = "Contact Email Address:")]
    [Remote("VerifyUniqueEmail", "Home")]
    public string Email { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "New Password:")]
    public string NewPassword { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Confirm New Password:")]
    [System.ComponentModel.DataAnnotations.Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }

    public void Update(InvContext Context)
    {
      AgencyRepository agencyRepo = new AgencyRepository(Context);
      Agency agency = agencyRepo.Get(-1);
      if (agency == null)
        throw new System.Exception("There Is No Template Agency Available To Process Your Header Image.  Please Try Again Later");
      byte[] headerImage = agency.HeaderImage;
      byte[] backgroundImage = agency.BackgroundImage;

      // Create the Agency
      try
      {
        agency = new Agency();
        agency.Name = AgencyName;
        agency.Email = Email;
        agency.Actve = true;
        agency.HeaderImage = headerImage;
        agency.BackgroundImage = backgroundImage;
        agencyRepo.Add(agency);
        agencyRepo.Save();
        if (agency.ID < 1)
        {
          throw new System.Exception("Your Agency Could Not Be Created.  Please Try Again Later");
        }
      }
      catch (DbEntityValidationException e)
      {
        throw new System.Exception(e.InnerException == null ? e.Message : e.InnerException.Message);
      }
      catch (Exception e)
      {
        throw new System.Exception(e.InnerException == null ? e.Message : e.InnerException.Message);
      }

      // Create the new User Profile
      try
      {
        string token = WebSecurity.CreateUserAndAccount(Email, NewPassword, new
        {
          RegistrationCode = "",
          FirstName = FirstName,
          MiddleName = MiddleName == null ? "" : MiddleName,
          LastName = LastName,
          AgencyID = agency.ID,
          LastLogonDate = SqlDateTime.MinValue,
          Active = true,
          PostDisaster = false
        });
      }
      catch (Exception e)
      {
        throw new System.Exception(e.InnerException == null ? e.Message : e.InnerException.Message);
      }

      // Add the User to the Agent role
      try
      {
        Roles.AddUserToRole(Email, "Agent");
      }
      catch (Exception e)
      {
        throw new System.Exception(e.InnerException == null ? e.Message : e.InnerException.Message);
      }

      // Create the Inventory List for the new User
      try
      {
        UserProfileRepository upRepo = new UserProfileRepository(Context);
        GinkoBL.UserProfile user = upRepo.Get(Email);
        CaseRepository caseRepo = new CaseRepository(Context);

        SqlParameter userID = new SqlParameter("@UserProfileID", user.ID);
        SqlParameter Title = new SqlParameter("@Title", user.FirstName + " Inventory");
        Case case1 = Context.Database.SqlQuery<Case>("spCasesAdd @UserProfileID, @Title", userID, Title).FirstOrDefault();
        if (case1.ID < 1)
        {
          throw new System.Exception("Your Agency Could Not Be Created.  Please Try Again Later");
        }
      }
      catch (Exception e)
      {
        throw new System.Exception(e.InnerException == null ? e.Message : e.InnerException.Message);
      }
    }
  }
4

2 に答える 2