c# - Performing projections on multiple databases with only one dbContext -


we using ef.core current project. project has 3 databases real nuisance can't avoided. databases have same structure. able swap contexts , use same ef model crud operations.

we have 1 particularly complex query going porting on traditional ado.net raw sql. problem is cross database query. replicate issue need way have 3 tables query in question, 3 databases within same dbcontext.

absolute nightmare going, tried alot of stuff. did table per hierarchy (tph )stuff inheritance in ef core. don't believe can done regards multiple databases. here useful site used. http://learnentityframeworkcore.com/inheritance

so wondered if has decent information on can achieved using ef.

ok, believe have found way cross db queries using ef core execution happening on database , not in shared memory. shall stock system example. hope of use somebody.

first of synonyms need created sqlserver db, on master table, associated tables linked together.

then our ef models , derived classes should follows.

 public abstract class stock  {      public int id{get;set;}    public string stockname{get;set;}  }   [table("dbname.scheme.stock", schema = "dbo")]  public class winterstock : stock  {    public winterstock() : base() { }  }   [table("dbname.scheme.stock", schema = "dbo")]  public class summerstock : stock  {   public summerstock() : base() { }  } 

in our test method have...

  var query = _context.set<winterstock>().join(_context.set<summerstock>(), winterstock => winterstock.stockname,summerstock => summerstock.stockname, (summerstock,winterstock) => new { summerstock, winterstock });   var result = query.tolist(); 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -