none
Help with scaffolding MVC with Visual Basic (tons of hours into it and I can't get started)

    Question

  • I'm using VS 2015 community. I just updated to the latest sp.

    It lets me create a VB MVC project and model.

    But when I add scaffolding (MVC 5 Controller with views, using entity framework), I get the message

    "visual basic command line compiler has stopped working"

    Then I get the error with the red x

    "There was an error running the selected code generator: failed to render because of the following errors: an exception was thrown while trying to compile the transformation code (plus about 100 more lines that I can't copy because its displayed in a message box)"

    This works on my sons computer - and it works on my computer if I use the C# language. I suck at syntax, so I would rather use VB than C#.

    I've tried just about every possible combination of settings on the wizard. They all lead to the same error.

    Suggestions?

    Friday, January 1, 2016 5:19 PM

Answers

All replies

  • I would say don't drink the MS Kool Aid using EF right up there in the MVC controller. Yeah I know they teach it using Code First but it is bad news.

    You should learn how to use n-tier in using MVC where EF is setting behind a DAL, and you leave the EF entities at the DAL sending DTO(s) through the tiers.  

    I find using Code Frist and EF lead to a lot of trouble, and maybe you should consider using DB First which is another way of doing it. 

    Since you are talked C#, I'll give you C# where the model object is not based on EF with data annotations. Yes, the DAL is being called that is using EF, but the usage of EF is nowhere to be found in the MVC controller.

    using System.ComponentModel.DataAnnotations;
    namespace CEEPRebatePortal.Models.RebateWizardModels
    {
        public class SubmitterAddress
        {
            public int ID { get; set; }
    
            [Display(Name = "Company Name")]
            [Required(ErrorMessage = "Company Name field is required.")]
            [StringLength(255)]
            public string CompanyName { get; set; }
    
            [Required]
            [StringLength(500)]
            public string Address1 { get; set; }
    
            [StringLength(500)]
            public string Address2 { get; set; }
    
            [Required]
            [StringLength(50)]
            public string City { get; set; }
    
            [Required]
            public string State { get; set; }
    
            [Display(Name = "Zip")]
            [Required(ErrorMessage = "Zip code field is required.")]
            [StringLength(25)]
            public string PostalCode { get; set; }
        }
    }
    
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.Validation;
    using System.Linq;
    using System.Web.Mvc;
    using CEEPRebateDAL;
    using CEEPRebateEntities;
    using Castle.Core.Logging;
    using CEEPRebatePortal.Models.RebateSharedModels;
    using CEEPRebatePortal.Models.RebateWizardModels;
    using Microsoft.Ajax.Utilities;
    using Microsoft.AspNet.Identity;
    using System.Diagnostics;
    using CEEPRebatePortal.Models;
    using CEEPRebateCore;
    using AutoMapper;
    using CEEPRebateCore.HVACChiller;
    
    namespace CEEPRebatePortal.Controllers
    {
        [Authorize(Roles="Submitter")]
        public class RebateWizardController : BaseWebController
        {
            #region "Dependencies"
            public IRequestsDalMgr requestsDalMgr { get; set; }
            #endregion
    
            private const string ADDMODELSESSIONKEY = "addmodel";
    
            private const string ERRORMESSAGE = "Please fix the following errors:";
    
            [HttpGet]
            public ActionResult Index()
            {
                return RedirectToAction("Page1");
            }
    
            [HttpGet]
            public ActionResult Page1(int? copy)
            {
                RebateWizardPagesModel model = null;
    
                if (copy.HasValue)
                {
                    // try making a copy of an existing rebate request
                    model = new RebateWizardPagesModel();
    
                    DTORequest dto = requestsDalMgr.GetRequestByID(copy.Value);
                    if (dto.ID != 0)
                    {
                        // check that we have read access to it
                        RebateRequest requestToCopy = RebateFactory.MakeRebateRequest(dto);
                        if (RebateHelpers.CanUserViewRebate(requestToCopy, User))
                        {
                            // we found the existing rebate request; make a copy of it
                            // (Note that Submitter info will be overwritten later when the new rebate is saved.)
                            model = MapDTOToRebateWizardModels(dto);
                            model.CopyMessage = string.Format(
                                "This is a copy of rebate #{0}. You may modify any fields that differ from the original rebate request.", dto.RequestNumber);
                            Session[ADDMODELSESSIONKEY] = model;
                        }
                    }
                }
    
                if (model == null)
                {
                    model = GetOrSetModelFromSession();
                }
    
                return View(model);
            }
    
            [HttpPost]
            public ActionResult Page1(RebateWizardPagesModel addmodel, FormCollection formCollection)
            {
                if (RebateHelpers.IsbtnCancel(formCollection))
                {
                    Session[ADDMODELSESSIONKEY] = null;
                    return RedirectToAction("Index", "Rebate");
                }
     
                var model = GetOrSetModelFromSession();
                Session[ADDMODELSESSIONKEY] = model = MapPage1FormCollectionToPage1SessionObj(model, formCollection);
    
                if (model.Page1.WorkSiteSameAsCustomerAddress)
                {
                    // copy the Customer Address fields to the Work Site fields
                    model.Page1.WorkSiteAddress = Mapper.Map<CustomerAddress, WorkSiteAddress>(model.Page1.CustomerAddress);
                    Session[ADDMODELSESSIONKEY] = model;
    
                    // remove any model errors related to WorkSite
                    List<string> keysToRemove = ModelState.Where(x => x.Key.StartsWith("Page1.WorkSite")).Select(x => x.Key).ToList();
                    foreach (string key in keysToRemove)
                    {
                        ModelState.Remove(key);
                    }
    
                    // ensure that customer site is allowed as a work site
                    if (!string.IsNullOrWhiteSpace(model.Page1.CustomerAddress.State))
                    {
                        State workSiteState = model.Page1.WorkSiteStates.FirstOrDefault(x => x.DatabaseCode == model.Page1.CustomerAddress.State);
                        if (workSiteState == null)
                        {
                            ModelState.AddModelError("Page1.WorkSiteSameAsCustomerAddress",
                                "You must specify the Work Site address separately, because the Customer address is not in a state that is eligible for rebates.");
                        }
                    }
                }
                
                if (RebateHelpers.IsbtnNext(formCollection) && ModelState.IsValid)
                    return RedirectToAction("Page2");
    
                ViewBag.ErrorMsg = ERRORMESSAGE;
    
                return View(model);
            } 
    
            [HttpGet]
            public ActionResult Page2()
            {
                var model = Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel;
                if (model == null)
                {
                    // they skipped page 1
                    return RedirectToAction("Page1");
                }
    
                return View(model);
            }
    
            [HttpPost]
            public ActionResult Page2(RebateWizardPagesModel addmodel, FormCollection formCollection)
            {
                if (RebateHelpers.IsbtnCancel(formCollection))
                {
                    Session[ADDMODELSESSIONKEY] = null;
                    return RedirectToAction("Index", "Rebate");
                }
    
                var model = GetOrSetModelFromSession();
                Session[ADDMODELSESSIONKEY] = MapPage2FormCollectionToPage2SessionObj(model, formCollection);
    
                if (RebateHelpers.IsbtnPrev(formCollection) && ModelState.IsValid)
                    return RedirectToAction("Page1");
    
                if (RebateHelpers.IsbtnNext(formCollection) && ModelState.IsValid)
                    return RedirectToAction("Page3");
    
                ViewBag.ErrorMsg = ERRORMESSAGE;
    
                return View(Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel);
            }
    
            [HttpGet]
            public ActionResult Page3()
            {
                var model = Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel;
                if (model == null)
                {
                    // they skipped page 1
                    return RedirectToAction("Page1");
                }
    
                return View(model);
            }
    
            [HttpPost]
            public ActionResult Page3(RebateWizardPagesModel addmodel, FormCollection formCollection)
            {
                if (RebateHelpers.IsbtnCancel(formCollection))
                {
                    Session[ADDMODELSESSIONKEY] = null;
                    return RedirectToAction("Index", "Rebate");
                }
    
                var model = GetOrSetModelFromSession();
                Session[ADDMODELSESSIONKEY] = model = MapPage3FormCollectionToPage3SessionObj(model, formCollection);
    
                if (model.Page3.MailToSameAsDrawTo)
                {
                    // copy the Mail To fields to the Draw To fields
                    model.Page3.MailCheckAddress = Mapper.Map<DrawCheckAddress, MailCheckAddress>(model.Page3.DrawCheckAddress);
                    model.Page3.MailCheckContact = Mapper.Map<DrawCheckContact, MailCheckContact>(model.Page3.DrawCheckContact);
                    Session[ADDMODELSESSIONKEY] = model;
    
                    // remove any model errors related to Mail To
                    List<string> keysToRemove = ModelState.Where(x => x.Key.StartsWith("Page3.MailCheck")).Select(x => x.Key).ToList();
                    foreach (string key in keysToRemove)
                    {
                        ModelState.Remove(key);
                    }
                }
    
                if (RebateHelpers.IsbtnPrev(formCollection) && ModelState.IsValid)
                    return RedirectToAction("Page2");
    
                if (RebateHelpers.IsbtnSubmit(formCollection) && ModelState.IsValid)
                {
                    var errors = model.Validate();
    
                    if (errors.Count > 0)
                    {
                        foreach (var item in errors)
                        {
                            ModelState.AddModelError(item.ErrorPagePath, item.ErrorDesc); 
                        }
                    }
    
                    if (errors.Count == 0)
                    {
                        int newRebateId = DoSubmit(model);
                        return RedirectToAction("Worksheet", "Rebate", new { id = newRebateId });
                    }
                }
    
                ViewBag.ErrorMsg = ERRORMESSAGE;
    
                return View(Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel);
            }
    
           
            #region "Private Methods"
    
            /// <summary>
            /// Handles the final creation of the rebate on the last page of the wizard.
            /// </summary>
            /// <param name="model">model for all the wizard pages</param>
            /// <returns>rebate id if successful, null if failure</returns>
            private int DoSubmit(RebateWizardPagesModel model)
            {
                // map the view models to a DTO
                DTORequest dto = MapWizardSessionObjToDTO(Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel);
    
                // add the submitter info
                AddSubmitterInfoToDTO(dto);
    
                // get rebate category and region
                RebateCategory category = RebateHelpers.RebateCategoryFromString(dto.Category);
                Debug.Assert(category != RebateCategory.None);  // should have already been validated
    
                State state = State.FromDatabaseCode(dto.DTOWorkSiteAddress.State);
                Debug.Assert(state != null);    // should have already been validated
                RebateRegion region = state.ToRebateRegion();
                Debug.Assert(region != RebateRegion.None);  // should have already been validated
                dto.Region = region.ToString();
    
                // is this rebate eligible for contractor payments?
                dto.ContractorPmtEligible = RebateHelpers.IsNewRebateEligibleForContractorPayment(category, region, dto.CreateDate);
    
                // add a row of the appropriate type to the database as well
                switch (category)
                {
                    case RebateCategory.HVAC:
                        dto.DTOHvacRequest = new DTOHvacRequest();
                        break;
    
                    case RebateCategory.Chiller:
                        dto.DTOChillerRequest = new DTOChillerRequest();
                        break;
                }
    
                // add a fixture of the appropriate type, to get the worksheet started
                switch (category)
                {
                    case RebateCategory.HVAC:
                        {
                            dto.DTOFixtures = new List<DTOFixture>();
                            dto.DTOFixtures.Add(HvacFixture.MakeNewDTO());
                        }
                        break;
    
                    case RebateCategory.Chiller:
                        {
                            dto.DTOFixtures = new List<DTOFixture>();
                            dto.DTOFixtures.Add(ChillerFixture.MakeNewDTO());
                        }
                        break;
                }
    
                int newid = Save(dto);
                Session[ADDMODELSESSIONKEY] = null;
                return newid;
            }
    
            private RebateWizardPagesModel GetOrSetModelFromSession()
            {
                var model = Session[ADDMODELSESSIONKEY] as RebateWizardPagesModel;
                if (model == null)
                {
                    DTORequest dto = requestsDalMgr.ReturnNewRequestDTO();
    
                    // copy info from current user to Submitter, Contractor, Draw Check To, and Mail Check To fields
                    AddProfileInfoToDTO(dto);
    
                    model = MapDTOToRebateWizardModels(dto);
    
                    Session[ADDMODELSESSIONKEY] = model;
                }
                return model;
            }
    
            private Int32 Save(DTORequest dto)
            {
                return requestsDalMgr.SaveRequest(dto);
            }
    
            private RebateWizardPagesModel MapDTOToRebateWizardModels(DTORequest dto)
            {
                var rwpm = new RebateWizardPagesModel
                {
                    Page1 =
                    {
                        Category = dto.Category,
                        ProjectDescription = dto.AdminNote,
                        CustomerAccountNumber = dto.CustomerAccountNumber,
                        CustomerAddress = Mapper.Map<DTOAddress, CustomerAddress>(dto.DTOCustomerAddress),
                        CustomerContact = Mapper.Map<DTOContact, CustomerContact>(dto.DTOCustomerContact),
                        WorkSiteAddress = Mapper.Map<DTOAddress, WorkSiteAddress>(dto.DTOWorkSiteAddress)
                    },
    
                    Page2 =
                    {
                        ContractorAddress = Mapper.Map<DTOAddress, ContractorAddress>(dto.DTOContractorAddress), 
                        ContractorContact = Mapper.Map<DTOContact, ContractorContact>(dto.DTOContractorContact)
                    },
    
                   Page3 = 
                    {
                        DrawCheckAddress = Mapper.Map<DTOAddress, DrawCheckAddress>(dto.DTODrawCheckAddress),
                        DrawCheckContact = Mapper.Map<DTOContact, DrawCheckContact>(dto.DTODrawCheckContact),
                        MailCheckAddress = Mapper.Map<DTOAddress, MailCheckAddress>(dto.DTOMailCheckAddress), 
                        MailCheckContact = Mapper.Map<DTOContact, MailCheckContact>(dto.DTOMailCheckContact)
                    },
    
                };
    
                return rwpm;
            }
    
            /// <summary>
            /// Given a Request DTO, adds info about the current user as the submitter.
            /// Throws an exception if user info cannot be found, since this should never happen.
            /// </summary>
            /// <param name="dto"></param>
            private void AddSubmitterInfoToDTO(DTORequest dto)
            {
                Debug.Assert(User != null && User.Identity != null); // Authorize attribute should assure that we are logged in and that there is a User
                dto.SubmitterUserID = User.Identity.GetUserId();
    
                // get submitter contact info and address from current user's profile
                var applicationUser = ApplicationUserManager.GetUserFromId(dto.SubmitterUserID);
                if (applicationUser == null)
                {
                    throw new ApplicationException(string.Format("Unable to find info for user {0}; cannot submit rebate", dto.SubmitterUserID));
                }
                dto.DTOSubmitterContact = new DTOContact()
                {
                    PersonName = applicationUser.FullName,
                    EmailAddress = applicationUser.UserName,
                    PhoneNumber = applicationUser.Phone
                };
                dto.DTOSubmitterAddress = new DTOAddress()
                {
                    CompanyName = applicationUser.CompanyName,
                    Address1 = applicationUser.Address1,
                    Address2 = applicationUser.Address2,
                    City = applicationUser.City,
                    State = applicationUser.State,
                    PostalCode = applicationUser.ZipCode
                };
            }
    
            /// <summary>
            /// Given a Request DTO, adds info about the current user as the contractor, draw-check-to, and mail-check-to.
            /// Throws an exception if user info cannot be found, since this should never happen.
            /// </summary>
            /// <param name="dto"></param>
            private void AddProfileInfoToDTO(DTORequest dto)
            {
                Debug.Assert(User != null); // Authorize attribute should assure that we are logged in and that there is a User
                string userId = User.Identity.GetUserId();
    
                // get contact info and address from current user's profile
                var applicationUser = ApplicationUserManager.GetUserFromId(userId);
                if (applicationUser == null)
                {
                    throw new ApplicationException(string.Format("Unable to find info for user {0}; cannot submit rebate", userId));
                }
                dto.DTOContractorContact = new DTOContact()
                {
                    PersonName = applicationUser.FullName,
                    EmailAddress = applicationUser.UserName,
                    PhoneNumber = applicationUser.Phone
                };
                dto.DTOContractorAddress = new DTOAddress()
                {
                    CompanyName = applicationUser.CompanyName,
                    Address1 = applicationUser.Address1,
                    Address2 = applicationUser.Address2,
                    City = applicationUser.City,
                    State = applicationUser.State,
                    PostalCode = applicationUser.ZipCode
                };
    
                // OK to copy these by reference, since we are going to map the DTO to a model and then throw it away
                dto.DTODrawCheckContact = dto.DTOContractorContact;
                dto.DTODrawCheckAddress = dto.DTOContractorAddress;
                dto.DTOMailCheckContact = dto.DTOContractorContact;
                dto.DTOMailCheckAddress = dto.DTOContractorAddress;
            }
    
            private RebateWizardPagesModel MapPage1FormCollectionToPage1SessionObj(RebateWizardPagesModel sessionobj, FormCollection formCollection)
            {
        
                sessionobj.Page1.Category =  formCollection["Page1.Category"];
                sessionobj.Page1.ProjectDescription = formCollection["Page1.ProjectDescription"];
                sessionobj.Page1.CustomerAccountNumber = formCollection["Page1.CustomerAccountNumber"];
                sessionobj.Page1.CustomerAddress.CompanyName = formCollection["Page1.CustomerAddress.CompanyName"];
                sessionobj.Page1.CustomerAddress.Address1 = formCollection["Page1.CustomerAddress.Address1"];
                sessionobj.Page1.CustomerAddress.Address2 = formCollection["Page1.CustomerAddress.Address2"];
                sessionobj.Page1.CustomerAddress.City = formCollection["Page1.CustomerAddress.City"];
                sessionobj.Page1.CustomerAddress.State = formCollection["Page1.CustomerAddress.State"];
                sessionobj.Page1.CustomerAddress.PostalCode = formCollection["Page1.CustomerAddress.PostalCode"];
    
                sessionobj.Page1.CustomerAddress.PostalCode = formCollection["Page1.CustomerAddress.PostalCode"];
                sessionobj.Page1.CustomerContact.PersonName = formCollection["Page1.CustomerContact.PersonName"];
                sessionobj.Page1.CustomerContact.PhoneNumber = formCollection["Page1.CustomerContact.PhoneNumber"];
                sessionobj.Page1.CustomerContact.EmailAddress = formCollection["Page1.CustomerContact.EmailAddress"];
    
                sessionobj.Page1.WorkSiteSameAsCustomerAddress = WebHelpers.GetCheckBoxValueFromFormCollection(formCollection, "Page1.WorkSiteSameAsCustomerAddress");
                sessionobj.Page1.WorkSiteAddress.CompanyName = formCollection["Page1.WorkSiteAddress.CompanyName"];
                sessionobj.Page1.WorkSiteAddress.Address1 = formCollection["Page1.WorkSiteAddress.Address1"];
                sessionobj.Page1.WorkSiteAddress.Address2 = formCollection["Page1.WorkSiteAddress.Address2"];
                sessionobj.Page1.WorkSiteAddress.City = formCollection["Page1.WorkSiteAddress.City"];
                sessionobj.Page1.WorkSiteAddress.State = formCollection["Page1.WorkSiteAddress.State"];
                sessionobj.Page1.WorkSiteAddress.PostalCode = formCollection["Page1.WorkSiteAddress.PostalCode"];
    
                return sessionobj;
            }
    
            private RebateWizardPagesModel MapPage2FormCollectionToPage2SessionObj(RebateWizardPagesModel sessionobj, FormCollection formCollection)
            {
                sessionobj.Page2.ContractorAddress.CompanyName = formCollection["Page2.ContractorAddress.CompanyName"];
                sessionobj.Page2.ContractorAddress.Address1 = formCollection["Page2.ContractorAddress.Address1"];
                sessionobj.Page2.ContractorAddress.Address2 = formCollection["Page2.ContractorAddress.Address2"];
                sessionobj.Page2.ContractorAddress.City = formCollection["Page2.ContractorAddress.City"];
                sessionobj.Page2.ContractorAddress.State = formCollection["Page2.ContractorAddress.State"];
                sessionobj.Page2.ContractorAddress.PostalCode = formCollection["Page2.ContractorAddress.PostalCode"];
    
                sessionobj.Page2.ContractorContact.PersonName = formCollection["Page2.ContractorContact.PersonName"];
                sessionobj.Page2.ContractorContact.PhoneNumber = formCollection["Page2.ContractorContact.PhoneNumber"];
                sessionobj.Page2.ContractorContact.EmailAddress = formCollection["Page2.ContractorContact.EmailAddress"];
          
                return sessionobj;
            }
    
            private RebateWizardPagesModel MapPage3FormCollectionToPage3SessionObj(RebateWizardPagesModel sessionobj, FormCollection formCollection)
            {
                sessionobj.Page3.DrawCheckAddress.CompanyName = formCollection["Page3.DrawCheckAddress.CompanyName"];
                sessionobj.Page3.DrawCheckAddress.Address1 = formCollection["Page3.DrawCheckAddress.Address1"];
                sessionobj.Page3.DrawCheckAddress.Address2 = formCollection["Page3.DrawCheckAddress.Address2"];
                sessionobj.Page3.DrawCheckAddress.City = formCollection["Page3.DrawCheckAddress.City"];
                sessionobj.Page3.DrawCheckAddress.State = formCollection["Page3.DrawCheckAddress.State"];
                sessionobj.Page3.DrawCheckAddress.PostalCode = formCollection["Page3.DrawCheckAddress.PostalCode"];
    
                sessionobj.Page3.DrawCheckContact.PersonName = formCollection["Page3.DrawCheckContact.PersonName"];
                sessionobj.Page3.DrawCheckContact.PhoneNumber = formCollection["Page3.DrawCheckContact.PhoneNumber"];
                sessionobj.Page3.DrawCheckContact.EmailAddress = formCollection["Page3.DrawCheckContact.EmailAddress"];
    
                sessionobj.Page3.MailToSameAsDrawTo = WebHelpers.GetCheckBoxValueFromFormCollection(formCollection, "Page3.MailToSameAsDrawTo");
                sessionobj.Page3.MailCheckAddress.CompanyName = formCollection["Page3.MailCheckAddress.CompanyName"];
                sessionobj.Page3.MailCheckAddress.Address1 = formCollection["Page3.MailCheckAddress.Address1"];
                sessionobj.Page3.MailCheckAddress.Address2 = formCollection["Page3.MailCheckAddress.Address2"];
                sessionobj.Page3.MailCheckAddress.City = formCollection["Page3.MailCheckAddress.City"];
                sessionobj.Page3.MailCheckAddress.State = formCollection["Page3.MailCheckAddress.State"];
                sessionobj.Page3.MailCheckAddress.PostalCode = formCollection["Page3.MailCheckAddress.PostalCode"];
    
                sessionobj.Page3.MailCheckContact.PersonName = formCollection["Page3.MailCheckContact.PersonName"];
                sessionobj.Page3.MailCheckContact.PhoneNumber = formCollection["Page3.MailCheckContact.PhoneNumber"];
                sessionobj.Page3.MailCheckContact.EmailAddress = formCollection["Page3.MailCheckContact.EmailAddress"];
    
                return sessionobj;
            }
    
            private DTORequest MapWizardSessionObjToDTO(RebateWizardPagesModel sessobj)
            {
                var dto = new DTORequest
                {
                    Category = sessobj.Page1.Category,
                    AdminNote = sessobj.Page1.ProjectDescription,
                    SubmitterUserID = sessobj.Page1.SubmitterUserID,
                    CreateDate = DateTime.Now,
                    CustomerAccountNumber = sessobj.Page1.CustomerAccountNumber,
                    DTOCustomerContact = Mapper.Map<CustomerContact, DTOContact>(sessobj.Page1.CustomerContact),
                    DTOCustomerAddress = Mapper.Map<CustomerAddress, DTOAddress>(sessobj.Page1.CustomerAddress),
                    DTOWorkSiteAddress = Mapper.Map<WorkSiteAddress, DTOAddress>(sessobj.Page1.WorkSiteAddress),
                    DTOContractorContact = Mapper.Map<ContractorContact, DTOContact>(sessobj.Page2.ContractorContact),
                    DTOContractorAddress = Mapper.Map<ContractorAddress, DTOAddress>(sessobj.Page2.ContractorAddress),
                    DTODrawCheckContact = Mapper.Map<DrawCheckContact, DTOContact>(sessobj.Page3.DrawCheckContact),
                    DTODrawCheckAddress = Mapper.Map<DrawCheckAddress, DTOAddress>(sessobj.Page3.DrawCheckAddress),
                    DTOMailCheckContact = Mapper.Map<MailCheckContact, DTOContact>(sessobj.Page3.MailCheckContact),
                    DTOMailCheckAddress = Mapper.Map<MailCheckAddress, DTOAddress>(sessobj.Page3.MailCheckAddress)
                };
    
                return dto;
            }
    
            #endregion
    	}
    }
    
    
    

    Friday, January 1, 2016 8:03 PM
  • I think you misunderstood my issue.

    I can't get the scaffolding wizard to work using Visual Basic. That's my issue. I've spent a ton of time learning C# (or attempting to learn it) and have decided I want to use Visual Basic. I at least want to get the wizard to work in VB so I can compare the code it writes to the code in C#.

    I have 600 points in MVA after just starting a month ago. But I haven't done anything productive yet. I'm hoping I didn't waste all those hours.  I'm ready to be productive.

    Friday, January 1, 2016 11:37 PM
  • I can't get the scaffolding wizard to work using Visual Basic. That's my issue. I've spent a ton of time learning C# (or attempting to learn it) and have decided I want to use Visual Basic. I at least want to get the wizard to work in VB so I can compare the code it writes to the code in C#.

    Oh, a wizard no wonder as Mr. Wizard strikes again. You don't need Mr. Wizard on something one can do his or herself.

    Saturday, January 2, 2016 12:20 AM
  • Hello,

    This sounds more like an issue with Visual Studio rather than vb.net as "visual basic command line compiler has stopped working" since it works on your son's computer is not a language specific issue but within Visual Studio so I am moving this thread to the Visual Studio forum. Hopefully those in this forum can assist you with this issue.

    You might want to indicate if your son's computer has been updated as your's was too.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    Saturday, January 2, 2016 2:29 AM
  • Hi Richie White,

    Thanks for your post.

    I did a test in my side using VS2015  Enterprise Update1. And it works well when adding the scaffolding.

    So according to the error message, here are some suggestions for you:

    1.If this is a Windows OS issue, you can check the latest Windows updates, and download and install it.

    2. If we are sure the cause is not in your Windows OS.

    Since the error occurred when adding the scaffolding even for a new created MVC project. I suppose this is probably the problem in your Visual Studio.

    In this case. I suggest you to check the installed products of your Visual Studio at first. And make sure the Visual Basic 2015 is installed successfully.

    You could find it in the following path: Help->About Microsoft Visual Studio

    Also  try to repair your VS then try it again, may be the issue will be solved.

    Or you could install the VS2015 Update1 then try it again.

    Best Regards,

    Lake Xiao
    Monday, January 4, 2016 8:58 AM
    Moderator
  • It didn't work with VS 2015, so I installed update 1 with the same results.

    How do I know if there's a problem with my OS? I haven't encountered any other issues.

    I'm using Windows 8.1. I'm sure upgrading to 10 would introduce new issues but could possibly get this working. I can't decide if its worth the risk.

    I may just give up and not use MVC/entity framework. If I can't get a head start with the wizard, it isn't worth it. I make too many mistakes.

    Don't know what else to try.

    Monday, January 4, 2016 5:06 PM
  • It didn't work with VS 2015, so I installed update 1 with the same results.

    How do I know if there's a problem with my OS? I haven't encountered any other issues.

    I'm using Windows 8.1. I'm sure upgrading to 10 would introduce new issues but could possibly get this working. I can't decide if its worth the risk.

    I may just give up and not use MVC/entity framework. If I can't get a head start with the wizard, it isn't worth it. I make too many mistakes.

    Don't know what else to try.

    What you do is leave the EF entities out of it.

    You create a custom class in the Model folder and apply the Data Annotations attributes to the class properties manually.

    You use AutoMapper in the Controller to map EF entity properties to the custom class properties,  and you reverse it mapping custom class back to the EF entity for data persistence to the DB using EF.

    http://www.codeproject.com/Articles/61629/AutoMapper

    It is the Model folder custom class/object you send into the View. The custom object may need to be in a List<T> since EF may be using a collection of objects it returned in a  List<T> on a Get/Read.

    You are depending upon the Wizard crutch to do it for you when you can just do it yourself. 

     
    Tuesday, January 5, 2016 1:39 AM
  • Hi Richie White,

    Is the error occurred when adding the scaffolding for all MVC projects?

    1. If the error only occurred for the specified MVC project.  I think the problem is probably in your MVC project.

    In this case, you may check if there is some custom class or another extension which affect it. Remove it and try it again.

    2. If the error occurred even for a new created MVC project.

    I suppose there is something wrong with the installation of your Visual Studio.

    In this case, could you please share us the installation log of your Visual Studio.

    I will check the installation log of your Visual Studio and check if there is some error during your VS installation.

    I suggest you could use the http://aka.ms/vscollect   tool to collect the installation logs. After using it, you will find vslogs.cab from %temp% folder.

    Then  upload the file to https://onedrive.live.com/    and share the link here.

    Best Regards,

    Lake Xiao


    Tuesday, January 5, 2016 5:30 AM
    Moderator
  • If I have to manually create add/delete/update/view pages for each table, it defeats the purpose of why I'm using the entity framework.

    I'm trying to learn this stuff and need to see the code it produces. If the wizard blows up, there't no telling what else isn't working. 

    Tuesday, January 5, 2016 4:55 PM
  • Here's a link.

    https://onedrive.live.com/redir?resid=389611368EC7B329!50619&authkey=!AIbx83-WlL0Y3U4&ithint=file%2czip

    Thanks

    Tuesday, January 5, 2016 4:58 PM
  • Hi Richie White,

    I just checked the log file you offered, and found there are several error message as below:

    MSI (s) (2C:54) [09:04:39:735]: Note: 1: 2205 2:  3: Error
    MSI (s) (2C:54) [09:04:39:735]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 22
    Action start 9:04:39: RemoveExistingProducts.
    MSI (s) (2C:54) [09:04:39:735]: Note: 1: 2205 2:  3: Error
    MSI (s) (2C:54) [09:04:39:735]: Note: 1: 2228 2:  3:Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 23

    It seems that VS installation is not completely ok and the corrupted MVC templates may lead to the issue.

    For this, you definitely should have a MVC Console application template under Visual Basic->Windows.

    You can try this to restore missing or corrupted templates:

    Please open Windows Explorer, and navigate to  <Visual Studio Installation Path>\Common7\IDE (by default is C:\Program Files \Microsoft Visual Studio 14.0\Common7\IDE);

    1.Delete the ItemTemplatesCache, ProjectTemplatesCache folder;

    2.Open Visual Studio Command Prompt  under Start menu -> All Programs -> Microsoft Visual Studio 2015 -> Visual Studio Tools (run it with Administrator privilege: right-click the program -> Run as administrator);

    3.Run the devenv /InstallVSTemplates switch;

    4.Run the devenv /Setup switch.

    If it still doesn't help, I suggest you use a healthy VS 2015 iso image to do a repair,

    VS 2015 iso Microsoft official download link:
    https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx
    VS 2015 iso files SHA-1 Values link:
    https://www.visualstudio.com/en-us/downloads/visual-studio-2015-iso-sha1-vs.aspx

    PS: To make sure whether your package is corrupted or not,
    please use FCIV.exe http://support.microsoft.com/kb/841290  to verify hash of the ISO.
    Any discrepancy would indicate that the file was corrupted. Here is a blog for how to use it, you can refer to it.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.

    Click HERE to participate the survey.

    Wednesday, January 6, 2016 5:25 AM
    Moderator
  • Thanks for your help.

    I tried the first steps - no change.

    I went to the first VS 2015 iso link you posted and reinstalled - no change.

    Should I try the 2nd link as well?

    Sunday, January 10, 2016 12:51 AM
  • If I have to manually create add/delete/update/view pages for each table, it defeats the purpose of why I'm using the entity framework.

    I'm trying to learn this stuff and need to see the code it produces. If the wizard blows up, there't no telling what else isn't working. 

    You are drinking the MS Kool Aid thinking that EF is supposed to be used up at the controller and in the View. I have seen enterprise level MVC solutions get hacked because of this concept.

    You don't understand SoC. 

    https://en.wikipedia.org/wiki/Separation_of_concerns

    You don't understand N-tier.

    https://en.wikipedia.org/wiki/Multitier_architecture

    http://www.codeproject.com/Articles/218729/Application-Security-in-n-tier-Application-on-Wind

    http://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En

    Sunday, January 10, 2016 3:30 AM
  • Agreed! There's a lot I don't understand.

    I also don't understand C# very well

    That's why I want to get the entity framework to create the code that the VB EF creates so that I can compare it with the code that the C# EF creates.

    Since the VB wizard locks up every time I attempt to scaffold, I assume something isn't working right.

    It's my experience that when a simple wizard locks up every time you do something, that it is very likely that other things will go wrong as well.

    I like my stuff to work.

    Monday, January 11, 2016 6:51 PM
  • That's why I want to get the entity framework to create the code that the VB EF creates so that I can compare it with the code that the C# EF creates.

    There is nothing that's going to be different :)

    I like my stuff to work.Well, uninstall/reinstall  VS then and see if it buys you anything.

    Tuesday, January 12, 2016 1:57 AM
  • I tried that
    Tuesday, January 12, 2016 4:40 AM
  • Are you saying that the C# code is identical to the VB code? That's nonsense.

    They are different languages.

    Tuesday, January 12, 2016 4:41 AM
  • Hi Richie White,

    Since you have tried repair, install VS2015 update1 and also tried the workaround offered by Lana Xu.

    May be the problem is not in your Visual Studio.

    You could also test it change another machine using same Visual Studio 2015.

    If it worked well when change another machine.

    I think the cause is more related to your Windows OS. Try to install the latest windows update then try it again.

    Hope that could be helpful to you.

    Best Regards,

    Lake Xiao


    Wednesday, January 13, 2016 9:24 AM
    Moderator
  • Are you saying that the C# code is identical to the VB code? That's nonsense.

    They are different languages.

    You don't know what you are talking about. Although they are different languages C# and VB.NET, they both are using the same common .NET objects out of the .NET Framework. 

    Therefore, they are not going to be too far apart on how each does the functionality and most likely no difference at all in the .NET .NET Framework objects being used. 

    You are sitting here talking about some Wizard acting like you know .NET? I kind of doubt it.

    Wednesday, January 13, 2016 12:18 PM
  • Did you read the title?

    I never meant to imply that I have experience. I'm simply wanting the wizard to run BECAUSE I don't have experience.

    Basically, all I have done is install VS, start a VB MVC project, make a model (using code first, existing database), and then attempt to use scaffolding to create the "MVC controller with views using Entity Framework".

    That's as far as I've ever gotten. At that point it gives me the Visual Basic Compiler error. I've tried it every way possible.

    Maybe I'm using the wrong terminology calling it a wizard? I'm the first to admit that I don't have much experience with VS.

    I can get past it doing the same thing in C#, but I want to do it in VB because I have some VB experience from the 90s.

    Friday, January 15, 2016 11:35 PM
  • That's as far as I've ever gotten. At that point it gives me the Visual Basic Compiler error. I've tried it every way possible.

    I am not reading every line in this thread. What are you talking about? What compile error?

    Saturday, January 16, 2016 2:33 AM
  • Please read the original post and ignore all the responses.
    Saturday, January 16, 2016 5:03 AM
  • Please read the original post and ignore all the responses.
    I would say use VB 2012 or 2015 Web Express edition as a workaround and see what happens.
    Saturday, January 16, 2016 3:55 PM
  • UPGRADED TO WINDOWS 10 AND NOW IT WORKS!!!!

    • Marked as answer by Richie White Thursday, January 21, 2016 11:37 PM
    Thursday, January 21, 2016 11:37 PM
  • UPGRADED TO WINDOWS 10 AND NOW IT WORKS!!!!

    Well, don't get too happy, because I am using Win10 pro on two machines in a home networking environment. One day the two machines can see each other, like doing RDP, MS SQL Server on one machine being seen by the other machine and accessible, file and print sharing can be done between the two NO PROBLEMS.

    And then these fecal matter crap stop doing it. The next day it works and it works until you do something that throws one of the O/S into a hissy fit, locks up and nothing works.  You can reboot both machines to the moon and back, and the fecal matter crap can't see each other. And then all of a sudden if one doesn't do anything for sometime with either one of them, this crap can see each other again.

    It's not a network problem. It's this junk called Win10.

    Friday, January 22, 2016 1:29 AM
  • So far I like Windows 10.

    It upgraded with no issues and fixed my VS issue.

    It seems like every other version of Windows is good. Windows 3.1 good, Windows 95 (not so good), Windows 98 good, Windows ME (not so good), Windows XP good, Windows Vista not so good, Windows 7 good, Windows 8 not so good, Windows 10 good.

    Friday, January 22, 2016 2:53 PM
  • So far I like Windows 10.

    It upgraded with no issues and fixed my VS issue.

    It seems like every other version of Windows is good. Windows 3.1 good, Windows 95 (not so good), Windows 98 good, Windows ME (not so good), Windows XP good, Windows Vista not so good, Windows 7 good, Windows 8 not so good, Windows 10 good.

    I should have stayed at Window 8 pro, but I took a chance on Win 10 knowing I should have waited at least 1 yr before I went to it.

    You'll find out when Win 10 goes off into La la land,  and you can't get it back other than, turn it off and back on,  or the computer has a Reset button.

    Friday, January 22, 2016 11:00 PM