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

Support arrays of related entity types #20615

Closed
bcallaghan-et opened this issue Apr 13, 2020 · 1 comment
Closed

Support arrays of related entity types #20615

bcallaghan-et opened this issue Apr 13, 2020 · 1 comment

Comments

@bcallaghan-et
Copy link

I have several classes that contain an array of linked items that should be stored in a separate table, using foreign keys to maintain a reference back to their parent. For example:

public class MyEntity
{
    public int Id { get; set; }
    public LinkedEntity[] LinkedItems { get; set; }
}

[Owned]
public class LinkedEntity
{
    public string Name { get; set; }
    public int Value { get; set; }
}

This setup builds the correct model and migrations, but fails at runtime if the array actually contains values. If I replace LinkedEntity[] with ICollection<LinkedEntity>, there are no errors, and the data is stored appopriately. However, the real MyEntity class is auto-generated and used by XmlSerializer which only supports collections that are arrays.

I would like to see arrays treated the same as any other collection type. They are already treated as such when building the model. Why are they treated any differently at runtime?

@ajcvickers
Copy link
Contributor

@bcallaghan-et EF needs a collection type that can have items added to it. Arrays can't be used because they are always a fixed size and the ICollection.Add method always throws.

Implementation of #2919 would allow this, so this is likely a duplicate of that issue--we will discuss.

@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

2 participants