1

I am using EntityFramework for an existing Database i have created . I have used one view using model based view and i've got an error after deleting the own model page view. Again went for creating EntityFramework using generate View, i am getting an error like this

Error

There was an error running the selected code generator

Exception has thrown By the target of an invocation

Previous version was working well. After connected database using appsettings then created model . Creating own view getting error deleted my own view file. Again using EntityFramework i am getting error above like this.

code:

<connectionStrings>
 <add name="tickandtieEntities" connectionString="metadata=res://*/Entityframework.Tickmarks.csdl|res://*/Entityframework.Tickmarks.ssdl|res://*/Entityframework.Tickmarks.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=DESKTOP-QD6A981\SQLEXPRESS;initial catalog=tickandtie;user id=sa;password=root;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>




namespace Inspinia_MVC5.Entityframework
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Data.Entity.Core.Objects;
    using System.Linq;

    public partial class tickandtieEntities : DbContext
    {
        public tickandtieEntities()
            : base("name=tickandtieEntities")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public virtual DbSet<Role> Roles { get; set; }
        public virtual DbSet<TP_EBITDA> TP_EBITDA { get; set; }
        public virtual DbSet<TP_EBITDA_Ratio> TP_EBITDA_Ratio { get; set; }
        public virtual DbSet<TP_InternalClients> TP_InternalClients { get; set; }
        public virtual DbSet<TP_Profile> TP_Profile { get; set; }
        public virtual DbSet<TP_ProjectFiles> TP_ProjectFiles { get; set; }
        public virtual DbSet<TP_Projects> TP_Projects { get; set; }
        public virtual DbSet<TP_ReportType> TP_ReportType { get; set; }
        public virtual DbSet<TP_Roles> TP_Roles { get; set; }
        public virtual DbSet<TP_Users> TP_Users { get; set; }
        public virtual DbSet<User> Users { get; set; }
        public virtual DbSet<TP_Chatter> TP_Chatter { get; set; }

        public virtual ObjectResult<AddChatter_Result> AddChatter(Nullable<int> projectId, Nullable<int> userId, string userName, string content)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            var userIdParameter = userId.HasValue ?
                new ObjectParameter("UserId", userId) :
                new ObjectParameter("UserId", typeof(int));

            var userNameParameter = userName != null ?
                new ObjectParameter("UserName", userName) :
                new ObjectParameter("UserName", typeof(string));

            var contentParameter = content != null ?
                new ObjectParameter("Content", content) :
                new ObjectParameter("Content", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<AddChatter_Result>("AddChatter", projectIdParameter, userIdParameter, userNameParameter, contentParameter);
        }

        public virtual ObjectResult<EventReport_Result> EventReport()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<EventReport_Result>("EventReport");
        }

        public virtual ObjectResult<ExpenseReport_Result> ExpenseReport()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ExpenseReport_Result>("ExpenseReport");
        }

        public virtual ObjectResult<GetChatterList_Result> GetChatterList(Nullable<int> projectId)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetChatterList_Result>("GetChatterList", projectIdParameter);
        }

        public virtual ObjectResult<GetClientsDetail_Result> GetClientsDetail(Nullable<bool> clientId)
        {
            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(bool));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetClientsDetail_Result>("GetClientsDetail", clientIdParameter);
        }

        public virtual ObjectResult<GetEbitDaList_Result> GetEbitDaList()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetEbitDaList_Result>("GetEbitDaList");
        }

        public virtual ObjectResult<GetEbitDaRatioList_Result> GetEbitDaRatioList()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetEbitDaRatioList_Result>("GetEbitDaRatioList");
        }

        public virtual ObjectResult<GetEmployeeList_Result> GetEmployeeList(Nullable<bool> clientId)
        {
            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(bool));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetEmployeeList_Result>("GetEmployeeList", clientIdParameter);
        }

        public virtual ObjectResult<GetProjectDetail_Result> GetProjectDetail(Nullable<int> projectId)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetProjectDetail_Result>("GetProjectDetail", projectIdParameter);
        }

        public virtual ObjectResult<GetUserProfile_Result> GetUserProfile(Nullable<int> uid)
        {
            var uidParameter = uid.HasValue ?
                new ObjectParameter("uid", uid) :
                new ObjectParameter("uid", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<GetUserProfile_Result>("GetUserProfile", uidParameter);
        }

        public virtual ObjectResult<InternalClientsList_Result> InternalClientsList(Nullable<bool> isActive, Nullable<int> clientId)
        {
            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<InternalClientsList_Result>("InternalClientsList", isActiveParameter, clientIdParameter);
        }

        public virtual ObjectResult<MonthlyDetailReport_Result> MonthlyDetailReport(Nullable<int> month_number, string expenseType, string eventName)
        {
            var month_numberParameter = month_number.HasValue ?
                new ObjectParameter("Month_number", month_number) :
                new ObjectParameter("Month_number", typeof(int));

            var expenseTypeParameter = expenseType != null ?
                new ObjectParameter("ExpenseType", expenseType) :
                new ObjectParameter("ExpenseType", typeof(string));

            var eventNameParameter = eventName != null ?
                new ObjectParameter("eventName", eventName) :
                new ObjectParameter("eventName", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<MonthlyDetailReport_Result>("MonthlyDetailReport", month_numberParameter, expenseTypeParameter, eventNameParameter);
        }

        public virtual ObjectResult<MonthlyReport_Result> MonthlyReport()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<MonthlyReport_Result>("MonthlyReport");
        }

        public virtual ObjectResult<ProjectFilesList_Result> ProjectFilesList(Nullable<int> projectId, Nullable<int> clientId, Nullable<bool> isActive)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ProjectFilesList_Result>("ProjectFilesList", projectIdParameter, clientIdParameter, isActiveParameter);
        }

        public virtual ObjectResult<ProjectsList_Result> ProjectsList(Nullable<bool> isActive, Nullable<int> clientId, string employeeId)
        {
            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            var employeeIdParameter = employeeId != null ?
                new ObjectParameter("EmployeeId", employeeId) :
                new ObjectParameter("EmployeeId", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ProjectsList_Result>("ProjectsList", isActiveParameter, clientIdParameter, employeeIdParameter);
        }

        public virtual int RemoveFilesProject(string fileName, string filePath, Nullable<System.DateTime> uploadedDate, Nullable<bool> isActive, string updatedBy, Nullable<int> projectId, Nullable<int> fileId, Nullable<int> clientId)
        {
            var fileNameParameter = fileName != null ?
                new ObjectParameter("FileName", fileName) :
                new ObjectParameter("FileName", typeof(string));

            var filePathParameter = filePath != null ?
                new ObjectParameter("FilePath", filePath) :
                new ObjectParameter("FilePath", typeof(string));

            var uploadedDateParameter = uploadedDate.HasValue ?
                new ObjectParameter("UploadedDate", uploadedDate) :
                new ObjectParameter("UploadedDate", typeof(System.DateTime));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var updatedByParameter = updatedBy != null ?
                new ObjectParameter("UpdatedBy", updatedBy) :
                new ObjectParameter("UpdatedBy", typeof(string));

            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            var fileIdParameter = fileId.HasValue ?
                new ObjectParameter("FileId", fileId) :
                new ObjectParameter("FileId", typeof(int));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("RemoveFilesProject", fileNameParameter, filePathParameter, uploadedDateParameter, isActiveParameter, updatedByParameter, projectIdParameter, fileIdParameter, clientIdParameter);
        }

        public virtual ObjectResult<ReportTypeList_Result> ReportTypeList()
        {
            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ReportTypeList_Result>("ReportTypeList");
        }

        public virtual int SaveInternalClients(string clientName, string primaryContactName, string emailId, string primaryContact, string modifiedBy, Nullable<bool> isActive, Nullable<int> parentCompany)
        {
            var clientNameParameter = clientName != null ?
                new ObjectParameter("ClientName", clientName) :
                new ObjectParameter("ClientName", typeof(string));

            var primaryContactNameParameter = primaryContactName != null ?
                new ObjectParameter("PrimaryContactName", primaryContactName) :
                new ObjectParameter("PrimaryContactName", typeof(string));

            var emailIdParameter = emailId != null ?
                new ObjectParameter("EmailId", emailId) :
                new ObjectParameter("EmailId", typeof(string));

            var primaryContactParameter = primaryContact != null ?
                new ObjectParameter("PrimaryContact", primaryContact) :
                new ObjectParameter("PrimaryContact", typeof(string));

            var modifiedByParameter = modifiedBy != null ?
                new ObjectParameter("ModifiedBy", modifiedBy) :
                new ObjectParameter("ModifiedBy", typeof(string));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var parentCompanyParameter = parentCompany.HasValue ?
                new ObjectParameter("ParentCompany", parentCompany) :
                new ObjectParameter("ParentCompany", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SaveInternalClients", clientNameParameter, primaryContactNameParameter, emailIdParameter, primaryContactParameter, modifiedByParameter, isActiveParameter, parentCompanyParameter);
        }

        public virtual ObjectResult<SaveProjects_Result> SaveProjects(string projectName, Nullable<System.DateTime> startDate, Nullable<System.DateTime> endDate, Nullable<bool> isActive, Nullable<System.DateTime> createdDate, string createdBy, Nullable<System.DateTime> updatedDate, string updatedBy, Nullable<int> clientId, string employees, string reportType)
        {
            var projectNameParameter = projectName != null ?
                new ObjectParameter("ProjectName", projectName) :
                new ObjectParameter("ProjectName", typeof(string));

            var startDateParameter = startDate.HasValue ?
                new ObjectParameter("StartDate", startDate) :
                new ObjectParameter("StartDate", typeof(System.DateTime));

            var endDateParameter = endDate.HasValue ?
                new ObjectParameter("EndDate", endDate) :
                new ObjectParameter("EndDate", typeof(System.DateTime));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var createdDateParameter = createdDate.HasValue ?
                new ObjectParameter("CreatedDate", createdDate) :
                new ObjectParameter("CreatedDate", typeof(System.DateTime));

            var createdByParameter = createdBy != null ?
                new ObjectParameter("CreatedBy", createdBy) :
                new ObjectParameter("CreatedBy", typeof(string));

            var updatedDateParameter = updatedDate.HasValue ?
                new ObjectParameter("UpdatedDate", updatedDate) :
                new ObjectParameter("UpdatedDate", typeof(System.DateTime));

            var updatedByParameter = updatedBy != null ?
                new ObjectParameter("UpdatedBy", updatedBy) :
                new ObjectParameter("UpdatedBy", typeof(string));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            var employeesParameter = employees != null ?
                new ObjectParameter("Employees", employees) :
                new ObjectParameter("Employees", typeof(string));

            var reportTypeParameter = reportType != null ?
                new ObjectParameter("ReportType", reportType) :
                new ObjectParameter("ReportType", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<SaveProjects_Result>("SaveProjects", projectNameParameter, startDateParameter, endDateParameter, isActiveParameter, createdDateParameter, createdByParameter, updatedDateParameter, updatedByParameter, clientIdParameter, employeesParameter, reportTypeParameter);
        }

        public virtual int UpdateInternalClients(Nullable<int> clientId, string clientName, string primaryContactName, string emailId, string primaryContact, string modifiedBy, Nullable<bool> isActive, Nullable<int> parentCompany)
        {
            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            var clientNameParameter = clientName != null ?
                new ObjectParameter("ClientName", clientName) :
                new ObjectParameter("ClientName", typeof(string));

            var primaryContactNameParameter = primaryContactName != null ?
                new ObjectParameter("PrimaryContactName", primaryContactName) :
                new ObjectParameter("PrimaryContactName", typeof(string));

            var emailIdParameter = emailId != null ?
                new ObjectParameter("EmailId", emailId) :
                new ObjectParameter("EmailId", typeof(string));

            var primaryContactParameter = primaryContact != null ?
                new ObjectParameter("PrimaryContact", primaryContact) :
                new ObjectParameter("PrimaryContact", typeof(string));

            var modifiedByParameter = modifiedBy != null ?
                new ObjectParameter("ModifiedBy", modifiedBy) :
                new ObjectParameter("ModifiedBy", typeof(string));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var parentCompanyParameter = parentCompany.HasValue ?
                new ObjectParameter("ParentCompany", parentCompany) :
                new ObjectParameter("ParentCompany", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("UpdateInternalClients", clientIdParameter, clientNameParameter, primaryContactNameParameter, emailIdParameter, primaryContactParameter, modifiedByParameter, isActiveParameter, parentCompanyParameter);
        }

        public virtual ObjectResult<UpdateProjects_Result> UpdateProjects(Nullable<int> projectId, string projectName, Nullable<System.DateTime> startDate, Nullable<System.DateTime> endDate, Nullable<bool> isActive, Nullable<System.DateTime> createdDate, string createdBy, Nullable<System.DateTime> updatedDate, string updatedBy, Nullable<int> clientId, Nullable<bool> isAnalyticsStart, Nullable<bool> isAnalyticsEnd, string employees, string reportType)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            var projectNameParameter = projectName != null ?
                new ObjectParameter("ProjectName", projectName) :
                new ObjectParameter("ProjectName", typeof(string));

            var startDateParameter = startDate.HasValue ?
                new ObjectParameter("StartDate", startDate) :
                new ObjectParameter("StartDate", typeof(System.DateTime));

            var endDateParameter = endDate.HasValue ?
                new ObjectParameter("EndDate", endDate) :
                new ObjectParameter("EndDate", typeof(System.DateTime));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var createdDateParameter = createdDate.HasValue ?
                new ObjectParameter("CreatedDate", createdDate) :
                new ObjectParameter("CreatedDate", typeof(System.DateTime));

            var createdByParameter = createdBy != null ?
                new ObjectParameter("CreatedBy", createdBy) :
                new ObjectParameter("CreatedBy", typeof(string));

            var updatedDateParameter = updatedDate.HasValue ?
                new ObjectParameter("UpdatedDate", updatedDate) :
                new ObjectParameter("UpdatedDate", typeof(System.DateTime));

            var updatedByParameter = updatedBy != null ?
                new ObjectParameter("UpdatedBy", updatedBy) :
                new ObjectParameter("UpdatedBy", typeof(string));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            var isAnalyticsStartParameter = isAnalyticsStart.HasValue ?
                new ObjectParameter("IsAnalyticsStart", isAnalyticsStart) :
                new ObjectParameter("IsAnalyticsStart", typeof(bool));

            var isAnalyticsEndParameter = isAnalyticsEnd.HasValue ?
                new ObjectParameter("IsAnalyticsEnd", isAnalyticsEnd) :
                new ObjectParameter("IsAnalyticsEnd", typeof(bool));

            var employeesParameter = employees != null ?
                new ObjectParameter("Employees", employees) :
                new ObjectParameter("Employees", typeof(string));

            var reportTypeParameter = reportType != null ?
                new ObjectParameter("ReportType", reportType) :
                new ObjectParameter("ReportType", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<UpdateProjects_Result>("UpdateProjects", projectIdParameter, projectNameParameter, startDateParameter, endDateParameter, isActiveParameter, createdDateParameter, createdByParameter, updatedDateParameter, updatedByParameter, clientIdParameter, isAnalyticsStartParameter, isAnalyticsEndParameter, employeesParameter, reportTypeParameter);
        }

        public virtual ObjectResult<UploadFilesProject_Result> UploadFilesProject(Nullable<int> projectId, string fileName, string filePath, Nullable<System.DateTime> uploadedDate, Nullable<bool> isActive, string updatedBy, Nullable<int> clientId)
        {
            var projectIdParameter = projectId.HasValue ?
                new ObjectParameter("ProjectId", projectId) :
                new ObjectParameter("ProjectId", typeof(int));

            var fileNameParameter = fileName != null ?
                new ObjectParameter("FileName", fileName) :
                new ObjectParameter("FileName", typeof(string));

            var filePathParameter = filePath != null ?
                new ObjectParameter("FilePath", filePath) :
                new ObjectParameter("FilePath", typeof(string));

            var uploadedDateParameter = uploadedDate.HasValue ?
                new ObjectParameter("UploadedDate", uploadedDate) :
                new ObjectParameter("UploadedDate", typeof(System.DateTime));

            var isActiveParameter = isActive.HasValue ?
                new ObjectParameter("IsActive", isActive) :
                new ObjectParameter("IsActive", typeof(bool));

            var updatedByParameter = updatedBy != null ?
                new ObjectParameter("UpdatedBy", updatedBy) :
                new ObjectParameter("UpdatedBy", typeof(string));

            var clientIdParameter = clientId.HasValue ?
                new ObjectParameter("ClientId", clientId) :
                new ObjectParameter("ClientId", typeof(int));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<UploadFilesProject_Result>("UploadFilesProject", projectIdParameter, fileNameParameter, filePathParameter, uploadedDateParameter, isActiveParameter, updatedByParameter, clientIdParameter);
        }

        public virtual ObjectResult<validateuser_Result> validateuser(string username, string password)
        {
            var usernameParameter = username != null ?
                new ObjectParameter("username", username) :
                new ObjectParameter("username", typeof(string));

            var passwordParameter = password != null ?
                new ObjectParameter("password", password) :
                new ObjectParameter("password", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<validateuser_Result>("validateuser", usernameParameter, passwordParameter);
        }
    }
}

How can i fix this issues? I am using appsetting connection and EntityFramework

thenna
  • 423
  • 1
  • 5
  • 26
  • Have you executing Model First approach? Check inner exception detail and post it in your question, the source of exception seems unclear here. PS: EF related exception often thrown by missing `KeyAttribute` property for defining primary key inside your model class, check them also. – Tetsuya Yamamoto Jul 18 '16 at 08:21
  • Actually i have created view page using Entity framework previous after i added custom view page without Entity framework its Worked after came back again entity framework trying to create view showing error like this – thenna Jul 18 '16 at 08:26
  • Have you trying to create a bound view through Add > View and choosing template with either data context or model class binding before exception was thrown? The inner exception details can be found when EF unhandled exception was caught by clicking "View Detail" and point to "InnerException" part. – Tetsuya Yamamoto Jul 18 '16 at 08:42
  • i have tired this method showing error Like this – thenna Jul 18 '16 at 09:07
  • Check your EF connection string inside web.config file (see http://stackoverflow.com/questions/19920837/there-was-an-error-running-the-selected-code-generator-in-vs-2013-scaffolding for similar problem). Post your web.config file contents & DB context code on your question if necessary. – Tetsuya Yamamoto Jul 18 '16 at 09:49
  • i am using appsettings and web config – thenna Jul 18 '16 at 09:53

0 Answers0