Update model causes interface to be removed from DbContext when using Effort with Entity Framework

c# effort entity-framework-6 unit-testing

Question

In order to enable unit testing without a database connection, I am currently attempting to use Effort (https://effort.codeplex.com/) with my Entity Framework 6 application (see http://www.codeproject.com/Articles/460175/Two-strategies-for-testing-Entity-Framework-Effort). In my project, where this is the case, everything functionsDbContext with an interface, which is necessary for Effort, and the overloaded constructors:

namespace Cssd.IT.PortalIntegration.DataAccess.HR.Dao
{
    using System;
    using System.Data.Common;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

    public partial class HRADDbContext : DbContext, IHRADDbContext
    {
        public HRADDbContext() : base("name=HRADDbContext")
        {
        }        

        public HRADDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {
            this.Configuration.LazyLoadingEnabled = false;
        }

        public HRADDbContext(DbConnection connection)
            : base(connection, true)
        {
            this.Configuration.LazyLoadingEnabled = false;
        }

        public virtual DbSet<CCS_DEPT_TBL> CCS_DEPT_TBL { get; set; }
        public virtual DbSet<CCS_HR_AD_SYNC> CCS_HR_AD_SYNC { get; set; }
    }
}

The issue is that updating the.edmx By selecting "Update model from database...", the context file is generated to be:

namespace Cssd.IT.PortalIntegration.DataAccess.HR.Dao
{
    using System;
    using System.Data.Common;
    using System.Data.Entity;

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

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

        public virtual DbSet<CCS_DEPT_TBL> CCS_DEPT_TBL { get; set; }
        public virtual DbSet<CCS_HR_AD_SYNC> CCS_HR_AD_SYNC { get; set; }
    }
}

I must therefore manually update the above after going back.Context.cs every time, file. also eliminates[Key] using thePOCO CCS_DEPT_TBL file.

Is there a way to set up my Entity Framework project so that every time I change the model from the database, it doesn't throw away the interface and overload the constructors? TIA.

UPDATE:

Since the class is only partially complete, all I do is make sure the interface and overloaded constructors are placed in a different file that is not generated automatically.

2ND UPDATE

Got it? Good. I've put this as a separate file, taking theDEPTID from the initialPOCO file, but it continues to insert thatDEPTID because there are two errors in the produced file, the build fails after an update.DEPTID belonging to the same class:

namespace Cssd.IT.PortalIntegration.DataAccess.HR.Dao
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;

    public partial class CCS_DEPT_TBL
    {
        [Key]
        public string DEPTID { get; set; }
    }
}

So how do I stop it from producing?DEPTID as it is already present in the partial class file mentioned above, in the produced class file?

1
2
9/18/2015 7:13:45 PM

Accepted Answer

ZZZ_tmp
3
9/18/2015 7:49:05 PM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow