Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3280296
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:41:18+00:00 2026-05-17T19:41:18+00:00

Wierd question title… What i am trying to accomplish is pretty simple i think.

  • 0

Wierd question title…

What i am trying to accomplish is pretty simple i think.

I got 3 tables in the database,

BlogPost – BlogPostTagsConnection – Tags

The blogpost contains text, title, slug, author, id etc. The BlogPostTagsConnection contains the BlogPost id and the Tags id and finally the Tags contains tagid and tag.

So i tried to figure out how to insert a new record (and eventually to update one):

public void Create(BlogPost post)
{
  DB db = new DB();
  var matchingTags = from data in db.Tags
                               where (from tagsInPost in post.Tags select tagsInPost.TagName).Contains(data.Tag)
                               select new Tag() {TagId = data.TagID, TagName = data.Tag};

  var post2 = new DataBlogPost
                            {
                                Title = post.Title,
                                Text = post.Text,
                                Slug = post.Slug,
                                ShortDescription = post.ShortDescription,
                                Published = post.Published,
                                Author = post.Author
                            };
  db.DataBlogPosts.InsertOnSubmit(post2);
  ... <- insert the tags and retrieve the id from the tags and the blogpost
  ... <- insert the ids from the tags and blogposts to the blogpoststagsconnection table
  db.SubmitChanges();
}

First i am getting all the tags from the database that matches the tags that i wrote in my blogpost. The tags are saved in a List with Tags { TagID, Tag }.

Secondly i insert my new post into the database (post2).

After this i need to insert all the tags (that i have created with my blogpost), so if i wrote this in the tags textbox “tag1 tag2 tag3 tag4” and my database already contains tag1 and tag2, it should then create 2 new records, one for tag3 and one for tag4.

I then need to get the id from the generated blogpost somehow and also the id from the tag3 and tag4 to be able to insert those into the BlogPostTagsConnection.

But how do i get the ID back? or is there a simpler way to handle these inserts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:41:19+00:00Added an answer on May 17, 2026 at 7:41 pm

    Yes, if your FK relationships are properly set up and tables properly imported on your DBML surface, your DataBlogPost will have a property BlogPostTagsConnections (or similar) which you can populate with new (or existing, pulled from the same DataContext) BlogPostTagsConnection instances.

    Similarly BlogPostTagsConnection will have a property Tags which you can populate.

    When done, insert your DataBlogPost and all the relational data will be saved too. No need to worry about IDs, just add existing or new instances to these “relational” properties.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is kind of a weird question so my title is just as weird.
got a weird question for you based on some weird happenings on our site.
Sorry about the weird question title, but I don't really know what to call
Okay, the title is not saying too much, sorry. Essentially it's an Architecture Question
Antescript: I'm aware that there's a prior SO question whose title sounds like it
The title of the question might sound confused, but in fact.. it is! I
Again same question title but requirement is somewhat different. We have implemented push notification
The app in question is a simple sample program. In my view controller header,
I'm building a super simple PHP CMS, and have a question about formatting text...
i'm having the the post's title error when trying to write a file on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.