Interested in a question on the Entity Framework. I have two databases and there are tables with the same name in them.

How to make, that within one project to work with tables of both DB? It is with those tables whose names match

Auto-generated code

An exception

// 1 context

public partial class UGTU_TESTEntities : DbContext { public UGTU_TESTEntities() : base("name=UGTU_TESTEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<Gorod> Gorod { get; set; } public virtual DbSet<Raion> Raion { get; set; } public virtual DbSet<Region> Region { get; set; } public virtual DbSet<Strana> Strana { get; set; } public virtual DbSet<Street> Street { get; set; } } 

// 2 context

 public partial class UGTUTestForAddressEntities : DbContext { public UGTUTestForAddressEntities() : base("name=UGTUTestForAddressEntities") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { throw new UnintentionalCodeFirstException(); } public virtual DbSet<Gorod> Gorod { get; set; } public virtual DbSet<Raion> Raion { get; set; } public virtual DbSet<Region> Region { get; set; } public virtual DbSet<Strana> Strana { get; set; } public virtual DbSet<Street> Street { get; set; } public virtual DbSet<Address> Address { get; set; } public virtual DbSet<Okrug> Okrug { get; set; } public virtual DbSet<Zaved_stud> Zaved_stud { get; set; } public virtual DbSet<AddressCZS> AddressCZS { get; set; } } 

Unhandled exception of type "System.Data.Entity.Core.MetadataException" in EntityFramework.dll

Additional information: The specified scheme is not valid. Errors:

The comparison of the CLR type with the EDM type is ambiguous, since several CLR types correspond to the EDM "Raion" type. Previous found CLR type "IntegrationAddress.UGTU_TEST.Raion". Found CLR type "IntegrationAddress.UGTU.Raion".

The comparison of the CLR type with the EDM type is ambiguous, since several CLR types correspond to the type of the EDM "Strana" model. Previous found CLR type "IntegrationAddress.UGTU_TEST.Strana". Found CLR type "IntegrationAddress.UGTU.Strana".

The exception gets out when executing this code:

  using (var dbReal = new IntegrationAddress.UGTU.UGTUTestForAddressEntities()) { var stranas = dbReal.Strana.ToList(); var regs = dbReal.Region.ToList(); var areas = dbReal.Raion.ToList(); var towns = dbReal.Gorod.ToList(); var streets = dbReal.Street.ToList(); var ads = dbReal.Address.ToList(); var adsCz = dbReal.AddressCZS.ToList(); var zavs = dbReal.Zaved_stud.ToList(); var oks = dbReal.Okrug.ToList(); } using (var dbTest = new IntegrationAddress.UGTU_TEST.UGTU_TESTEntities()) { var stranas = dbTest.Strana.ToList(); var regs = dbTest.Region.ToList(); var areas = dbTest.Raion.ToList(); var towns = dbTest.Gorod.ToList(); var streets = dbTest.Street.ToList(); } 
  • What's the problem? - Pavel Mayorov
  • the problem is that when 2 entities with the same name are found in contexts, an exception is thrown, although the contexts are different - Ivan Ulyashev
  • What is the exception? - Pavel Mayorov
  • one
    Why do you write the type names in transliteration? If you are doing this, why not in Cyrillic? C # supports source code in Unicode. - free_ze
  • one
    Rename your classes with any names, but just mark them with the attribute [Table("TableNameIdDBO")] - Vadim Prokopchuk

0