Skip to content
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

OwnedType throws error entity type is sharing the table #17165

Closed
cetk opened this issue Aug 15, 2019 · 2 comments
Closed

OwnedType throws error entity type is sharing the table #17165

cetk opened this issue Aug 15, 2019 · 2 comments

Comments

@cetk
Copy link

cetk commented Aug 15, 2019

I am using .net Core 2.2 and EFCOre 2.2.6 and having error for Owned Type

Hers is my code

public class StorageSummary
{
    public int Id { get; set; }
    public StorageDetailSummary Original { get; set; }
    public StorageDetailSummary Initial { get; set; }
    public StorageDetailSummary Accepted { get; set; }
}

[Owned]
public class StorageDetailSummary
{
    public decimal? PrimaryTow { get; set; }
    public decimal? LaborCost { get; set; }
}


  In dbcontext

                 modelBuilder.Entity<StorageSummary>(table =>
                {
                   table.OwnsOne(
                   a => a.Original, 
                  original =>
                 {
	           original.Property(x => x.PrimaryTow).HasColumnName("OriginalPrimaryTow");
                      original.Property(x => x.LaborCost).HasColumnName("OriginalLaborCost");
                });
            });

When I add to dbCOntext and SaveChanges I get the error as

The entity of type 'StorageSummary' is sharing the table 'StorageCheck.StorageSummaries' with entities of type 'StorageSummary.Initial#StorageDetailSummary', but there is no entity of this type with the same key value that has been marked as 'Added'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the key values.

@ajcvickers
Copy link
Member

Duplicate of #9005. In EF Core 2.2, when an owner and an owned type share the same table, then the owner must always have an associated owned type.

@kashania
Copy link

always you need to initialize the this StorageDetailSummary when you add it to the entity

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants