-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TPC scenario not supported #28015
Comments
@Luigi6821 Don't call modelBuilder.Entity<AMOS_ADDRESS>().UseTpcMappingStrategy();
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().UseTpcMappingStrategy();
modelBuilder.Entity<ADDRESS>().ToTable("ADDRESS", "AMOS");
modelBuilder.Entity<ADDRESSCONTACT>().ToTable("ADDRESSCONTACT"); Also, you can't yet configure a different column name for one of the tables, that's coming in #19811 |
Hi @AndriySvyryd public abstract class AMOS_ADDRESS
{
public decimal ADDRESSID { get; set; }
public string CODE { get; set; }
public string ALPHACODE { get; set; }
public List<AMOS_ADDRESSCONTACT> CONTACTS { get; set; }
}
public abstract class AMOS_ADDRESSCONTACT
{
public decimal ADDRESSCONTACTID { get; set; }
public AMOS_ADDRESS ADDRESS { get; set; }
public decimal ADDRESSID { get; set; }
}
public class ADDRESS : AMOS_ADDRESS
{ }
public class ADDRESSCONTACT : AMOS_ADDRESSCONTACT
{ }
... I tried configure it in this way: modelBuilder.Entity<AMOS_ADDRESS>().UseTpcMappingStrategy();
modelBuilder.Entity<ADDRESS>().ToTable("ADDRESS", "AMOS");
modelBuilder.Entity<ADDRESS>().HasKey(e => e.ADDRESSID);
modelBuilder.Entity<ADDRESS>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<ADDRESS>().Property(e => e.CODE).HasColumnName("CODE");
modelBuilder.Entity<ADDRESS>().Property(e => e.ALPHACODE).HasColumnName("ALPHACODE");
modelBuilder.Entity<ADDRESS>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<ADDRESS>().HasMany(e => e.CONTACTS);
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().UseTpcMappingStrategy();
modelBuilder.Entity<ADDRESSCONTACT>().ToTable("ADDRESSCONTACT");
modelBuilder.Entity<ADDRESSCONTACT>().HasKey(e => e.ADDRESSCONTACTID);
modelBuilder.Entity<ADDRESSCONTACT>().Property(e => e.ADDRESSCONTACTID).HasColumnName("ADDRESSCONTACTID");
modelBuilder.Entity<ADDRESSCONTACT>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<ADDRESSCONTACT>().HasOne(e => e.ADDRESS); But no luck: Please can you help me on how to configure model builder? Regards |
@Luigi6821 What provider are you using? The following configuration might work better: modelBuilder.Entity<AMOS_ADDRESS>().UseTpcMappingStrategy();
modelBuilder.Entity<AMOS_ADDRESS>().HasKey(e => e.ADDRESSID);
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.CODE).HasColumnName("CODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ALPHACODE).HasColumnName("ALPHACODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<ADDRESS>().ToTable("ADDRESS", "AMOS");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().UseTpcMappingStrategy();
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().HasKey(e => e.ADDRESSCONTACTID);
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().Property(e =>
e.ADDRESSCONTACTID).HasColumnName("ADDRESSCONTACTID");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().HasOne(e => e.ADDRESS);
modelBuilder.Entity<ADDRESSCONTACT>().ToTable("ADDRESSCONTACT"); |
Hi @AndriySvyryd, I'm using SQL Server. This is the rest of the code: SqlConnection connection = new SqlConnection() var optionsBuilder = new DbContextOptionsBuilder(); connection.Open(); optionsBuilder.UseSqlServer(connection); .... Any suggestions? Thanks |
How do you create the |
The code I submitted is a simplification of a company software where the model is created using this approach which should be perfectly valid. Anyway module builder is simple instantiated : var modelBuilder = new ModelBuilder(); I tried using OnModelCreating and it works. Please can you give me solution using my approach? Regards |
Please provide a small self-contained repro project |
Here you go. |
Targeting SqlServer and using If you need to call |
I tried using SqlServerConventionSetBuilder... and made some progress but still an error.
=====> Error : System.InvalidOperationException: 'Sequence contains no matching element' Of course AMOS.ADDRESS and AMOS.ADDRESSCONTACT contain rows. |
@Luigi6821 You can debug SQL queries either by profiling in SSMS, calling |
Please provide the stack trace as well |
Here below stack trace. |
TPC is in nightly builds. It is not available in preview4 |
@AndriySvyryd , Regards |
You can use daily builds |
Hi,
Looking at the new build preview I was playing with TPC to check the following scenario:
`public abstract class AMOS_ADDRESS
{
public decimal ADDRESSID { get; set; }
....
modelBuilder.Entity<AMOS_ADDRESS>().ToTable("ADDRESS", "AMOS");
modelBuilder.Entity<AMOS_ADDRESS>().HasKey(e => e.ADDRESSID);
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.CODE).HasColumnName("CODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ALPHACODE).HasColumnName("ALPHACODE");
modelBuilder.Entity<AMOS_ADDRESS>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().ToTable("ADDRESSCONTACT");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().HasKey(e => e.ADDRESSCONTACTID);
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().Property(e => e.ADDRESSCONTACTID).HasColumnName("ADDRESSCONTACTID");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().Property(e => e.ADDRESSID).HasColumnName("ADDRESSID");
modelBuilder.Entity<AMOS_ADDRESSCONTACT>().HasOne(e => e.ADDRESS);`
The error I receive when I try to run
var o = dbContext.Set<ADDRESS>().OrderBy(a => a.ADDRESSID).Take(10);
is:
The corresponding CLR type for entity type 'AMOS_ADDRESS' cannot be instantiated, and there is no derived entity type in the model that corresponds to a concrete CLR type.
The same code is perfectly supported by EF6.
Is the TPC implementation still not yet completed ?
Regards
Luigi
Originally posted by @Luigi6821 in #3170 (comment)
The text was updated successfully, but these errors were encountered: