Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Edited Issue: TPT Cannot reference base type in derived type [1093]

$
0
0
Error reproduction steps:

1. Create a base type:

```
public class BaseType
{
public Guid Id { get; set; }
}
```

2. Create a derived type with a property of BaseType in it.

```
public class DerivedType: BaseType
{
public int SomeExtraProp { get; set; }
public BaseType Parent { get; set; }
}
```

3. Make the derived type to have its own table in context.

```
public class Context: DbContext
{
public DbSet<BaseType> BaseTypes { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<DerivedType>().ToTable("DerivedTypes");
}
}
```

This will cause the database creation to fail.
I tested this case on EF 5 and it works normally.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>