© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
89 replies
İrşat

EF 6 - Creating entity with n-n

    PostDtoWrite_2 newpost = new PostDtoWrite_2();
    newpost.Title = request.Title;
    newpost.PostDescription = request.PostDescription;
    newpost.LanguageId = request.LanguageId;
    newpost.AccountId = request.AccountId;
    newpost.PostTypeId = request.PostTypeId;
    newpost.CoverImage = request.CoverImage;
    newpost.PublishDate = DateTime.Now;
    newpost.UpdateDate = DateTime.Now;
    newpost.DeletedStatusId = 1;
    newpost.PostTypeId = 1;
    newpost.IsPublished = true;

    try{
        db.Posts.Add(mapper.Map<Post>(newpost));
        await db.SaveChangesAsync();
    } catch (Exception) {
        return Results.StatusCode(580);
    }

    return Results.Ok();
    PostDtoWrite_2 newpost = new PostDtoWrite_2();
    newpost.Title = request.Title;
    newpost.PostDescription = request.PostDescription;
    newpost.LanguageId = request.LanguageId;
    newpost.AccountId = request.AccountId;
    newpost.PostTypeId = request.PostTypeId;
    newpost.CoverImage = request.CoverImage;
    newpost.PublishDate = DateTime.Now;
    newpost.UpdateDate = DateTime.Now;
    newpost.DeletedStatusId = 1;
    newpost.PostTypeId = 1;
    newpost.IsPublished = true;

    try{
        db.Posts.Add(mapper.Map<Post>(newpost));
        await db.SaveChangesAsync();
    } catch (Exception) {
        return Results.StatusCode(580);
    }

    return Results.Ok();

I want to add "Tags" to this but there is no table for many to many in new versions of EF.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

EF Entity 'required' property
C#CC# / help
2y ago
❔ Need help with EF 6 Migrations
C#CC# / help
3y ago
❔ Updating EF entity with object containing optional properties
C#CC# / help
3y ago