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

Data denormalization in Ef Core and Azure Cosmos Db #33727

Open
xari-jjcolumb opened this issue May 15, 2024 · 1 comment
Open

Data denormalization in Ef Core and Azure Cosmos Db #33727

xari-jjcolumb opened this issue May 15, 2024 · 1 comment

Comments

@xari-jjcolumb
Copy link

How do I denormalize data in Ef Core with Azure cosmos db provider?

As shown in this documentation: https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/model-partition-example#v2-introducing-denormalization-to-optimize-read-queries

I need to denormalize an entity which also lives in another container:

   public class Post
   {
       public int Id { get; set; }
       public string Title { get; set; } = null!;
       public List<Hashtag> Hashtags { get; set; } = new List<Hashtag>();
   }

   public class Comment
   {
       public int Id { get; set; }
       public int PostId { get; set; }
       public string Text { get; set; } = null!;
       public List<Hashtag> Hashtags { get; set; } = new List<Hashtag>();
   }
   public class Hashtag
   {
       public int Id { get; set; }
       public string Title { get; set; } = null!;
       public int Puntuation { get; set; }
   }

So for faster queries I need to embed the Hashtag in the Comment and in the Post (this is just an example, not a real use case), but the hashtag lives in it's own container.

I know this it's not possible in Ef Core due to I'll se an error like this: 'The type 'Hashtag' cannot be marked as owned because a non-owned entity type with the same name already exists.'

Any solution?

@ajcvickers
Copy link
Member

Note for team: this is a case where it would be useful to be able to map the same CLR type as both an owned and a non-owned type. Complex types should not have this problem, which reduces the priority here somewhat.

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