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="data source=(local);initial catalog=JSAVIP;Integrated Security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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="data source=(local);initial catalog=fsmf2012;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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