-
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
Understand why EF Core thinks it needs a setter for TagsInPostsData
in gRPC model
#23703
Comments
/cc @JeremyLikness |
[Update: OLD, Deleted this repo and created a new repo, see update below] I've created a sample GitHub repo for my question where you can see where I get an error adding seed data for "Join entity type configuration". Error: "No backing field could be found for property 'Tag.Videos' and the property does not have a setter." Sample code copied from Microsoft Docs: "Model seed data can be provided for the join entity type by using anonymous types" I've updated my ' Everything compiles, and EF Core creates the TagVideo join table & seeds the Videos & Tags data when I comment out the 'join entity' code below. (last ' Part of the sample project ApplicationDbContext.cs file where the error occurs:
|
This is my problem: I think I should have something like the code below in But in So I can't use
|
I watched the EF Core Tour Pt2 on Channel9 "Deep Dive in Many to Many" and updated my code repository. Actually I've created a new one: The 3 most important files are:
This is a working Blazor WASM (Kestrel Hosted with SQLite DB) repo as long as I do not run (comment out) the code below in When I try to add records to the Join Table (in
The error is:
Adding other records to the tables ( |
I propose we close this issue. @JeepNL it looks to me like the problem is with the generated entities. The Not the best answer but let me know if you have any other questions and I will close to keep open accordingly. |
@JeremyLikness In the issue you mentioned (and sub issues in it) people are talking about gRPC and problems with JSON serialization/deserialization if I understand correctly. But probably I don't, because I don't get why they want to use JSON serialization/deserialization with gRPC. I like gRPC just because it isn't REST. I love the combination EF Core/gRPC for (in my case Blazor WASM) web apps, because it's fast, it's contract based, it does binary wire transfer, it's imo easier to use than JSON/REST (serialization/deserialization), has more possibilities (client/server streaming) and EF Core already autogenerates a lot of code from a protobuf (definition/contract) file. Maybe I'm one of the early adopters using this combination (gRPC/EFCore) where most people still are using REST, but I'm pretty sure this will change in the near future because of the many pro's with using gRPC. I'm searching all over the internet how to use Many to Many relationships with EF Core and gRPC but I can't find the info I'm looking for. I'm watching videos how to use EF Core in general (i.e. your ON.NET EF Core Tour EF Core episodes, love them!) and I just bought the book "Entity Framework Core in Action Second Edition" (MEAP / Manning / Jon P Smith) I know I've a lot to learn about C# and EF Core, but so far I've written several (simple) prototypes which are using EF Core/gRPC and it so much fun writing them and I've learned already a lot how to use EF Core with gRPC for database access except how to implement Many to Many relationships. You say "the But I think more questions will come in the future about how to use Many to Many relationships with EF Core and gRPC because of the benefits of gRPC over REST. That's also why I've created a special GitHub repo for this question so maybe I can help other devs with it. |
Notes for triage: Call stack:
/cc @ajcvickers |
@JeepNL @JeremyLikness Finally got time to dig into this. Firstly, I'm impressed that EF Core is able to get this far with mapping against the generated entity types by convention. However, the modelBuilder.Entity<Post>().Navigation(e => e.TagsInPostsData).HasField("tagsInPostsData_");
modelBuilder.Entity<Tag>().Navigation(e => e.PostsInTagsData).HasField("postsInTagsData_"); I want to keep this issue open to investigate why EF Core thinks it needs the setter or field access here, since it looks like the collections are initialized eagerly. |
@ajcvickers No problem! And we just had the Christmas/New Year holidays, so it is very understandable, I'm just glad I've found something which seems to be more an issue than a question so I'm not wasting your time. (this is my 'imposter syndrome' speaking, but no worries, I'm embracing it 😉) Tomorrow I'll try your |
Wow! I actually got goosebumps when I ran the App. This is so great! I've updated my BlazorWasmGrpcBlog GitHub Repo with some additional comments and links to the EF Core Deep Dive Pt2 video and your answer here. I've renamed TagsInPostsData in TagsInPostData (Post singular) and PostsInTagsData in PostsInTagData (/Shared/Protos/blog.proto) e.g. multiple tags in one post and vice versa |
TagsInPostsData
in gRPC model
I'm trying to configure a many-to-many relationship in my (Shared Folder) protobuf file with the
video.proto
code sample below. This code compiles and auto generates theApplicationDbContextModelSnapshot.cs / xxxx_InitialCreate.cs
and creates 'automagically' the extra (needed) table "TagVideo" (see below).I'm trying to add model seed data as described in the EF Core 5.x ' Many-to-Many' samples in Microsoft Docs
I'm having difficulties implementing this, mainly because a) I'm learning 😉 & b) because EF Core auto generates the code/table I do not have the 'TagVideo' class. I don't know how to configure this in
ApplicationDbContext.cs
/ in my Blazor web application.File: video.proto
In ApplicationDbContextModelSnapshot.cs
In 20201216131125_InitialCreate.cs
The text was updated successfully, but these errors were encountered: