1

I have 2 similar DBs. So, both DBs have tables AllowedDates and AllowedTimes (with the same structore). I try to connect to these 2 DBs in my project. I created first model (DB.edmx) for first DB and second model (TEX.edmx) for second DB. Also, I renamed to AllowedDateTex and AllowedTimeTex EntityTypes for TEX.edmx to prevent name conflict of classes. In result, I have error in any case on line:

        List<AllowedDateTex> allowedDatesTex = (from i in _dbContextTex.AllowedDateTexes select i).ToList();

Additional information: Could not find the conceptual model type for 'ITW2012Mobile.Models.AllowedDate'.

why it tries to use 'ITW2012Mobile.Models.AllowedDate' and how to fix it?

I use the latest version of EF.

[ADDED]

My connection strings:

<add name="DefaultConnection" connectionString="data source=(local);initial catalog=JSAVIP;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="ITW2012Entities" connectionString="metadata=res://*/Models.DB.csdl|res://*/Models.DB.ssdl|res://*/Models.DB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=JSAVIP;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
<add name="TexEntities" connectionString="metadata=res://*/Models.TEX.csdl|res://*/Models.TEX.ssdl|res://*/Models.TEX.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(local);initial catalog=fsmf2012;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

call a second model:

    TexEntities _dbContextTex;
    _dbContextTex = new TexEntities();
    var a = (from i in _dbContextTex.AllowedDateTexes select i).ToList();

(on third string I get the error "Additional information: Could not find the conceptual model type for 'ITW2012Mobile.Models.AllowedDate'.")

defined AllowedDateTex etc:

namespace ITW2012Mobile.Models
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;

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

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

        public DbSet<AllowedDateTex> AllowedDateTexes { get; set; }
        public DbSet<AllowedTimeTex> AllowedTimeTexes { get; set; }
    }
}

namespace ITW2012Mobile.Models
{
    using System;
    using System.Collections.Generic;

    public partial class AllowedDateTex
    {
        public AllowedDateTex()
        {
            this.AllowedTimes = new HashSet<AllowedTimeTex>();
        }

        public int DayID { get; set; }
        public System.DateTime Day { get; set; }

        public virtual ICollection<AllowedTimeTex> AllowedTimes { get; set; }
    }
}

namespace ITW2012Mobile.Models
{
    using System;
    using System.Collections.Generic;

    public partial class AllowedTimeTex
    {
        public int TimeID { get; set; }
        public int DayID { get; set; }
        public int Hour { get; set; }
        public int Minute { get; set; }

        public virtual AllowedDateTex AllowedDate { get; set; }
    }
}

EDIT 2:

I decided to remove EF-models at all and recreate it. When I add first EF-model - all is ok. When I add one more with tables, which have the same names, as in first EF-model then classes from first model are recreated!

Thanks

Oleg Sh
  • 8,496
  • 17
  • 89
  • 159
  • You try using fully qualified names, e.g. Namespace.Namespace.AllowedDateTex? – MatthewMartin Oct 07 '14 at 15:15
  • It will help to post your connection strings (web.config) so we can follow from the very root of everything. Also, if you can post the database call you are making with the other database. Does that one work or do both not work? – Termato Oct 07 '14 at 17:16
  • post is edited. Please, look at it – Oleg Sh Oct 09 '14 at 15:01

0 Answers0