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

  • Home
  • SEARCH
  • 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 259391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:15:37+00:00 2026-05-11T22:15:37+00:00

I am using VB.NET with LINQ to MS SQL. I have two following tables.

  • 0

I am using VB.NET with LINQ to MS SQL.
I have two following tables. Now I want to insert multiple items in Tags Table using LINQ, but also wants to check that if any of tag exists in Tags table. It doesn’t insert it again and bring the TagID in both cases (if inserted or if found existed)

CREATE TABLE Tags
    (TagID bigint not null , 
    Tag varchar(100) NULL )

CREATE TABLE VideoTags
    (VideoID bigint not null , 
    TagID bigint not null )

What’s the best way to acheive this using LINQ?

Thanks in advance

  • 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-11T22:15:37+00:00Added an answer on May 11, 2026 at 10:15 pm

    LINQ is a query technology, but I think we know what you mean; you might want to be a bit more specific whether this is LINQ-to-SQL or Entity Framework. You might also want to clarify what “bulk” means in your case… for 10-100 records you might use a different answer to 10,000 records (where SqlBulkCopy into a staging table and a stored procedure to import at the db would be the best idea).

    For a relatively low number – just use your ORM tool to find the records – for example with LINQ-to-SQL (perhaps with a spanning serializable transaction) – and using C# for illustration (updated to show loop and cache):

    Dictionary<string,Tag> knownTags = new Dictionary<string,Tag>();
    foreach(... your data ...) {
        Tag tag;
        if(!knownTags.TryGetValue(tagName, out tag)) {
            tag = ctx.Tags.SingleOrDefault(t => t.Name == tagName);
            if(tag == null) {
                tag = new Tag { Name = tagName };
                ctx.Tags.InsertOnSubmit(tag);
            }
            knownTags.Add(tagName, tag);
        }
        // insert video tag
    }
    ctx.SubmitChanges();
    

    Actually, for performance reasons I wonder whether this might be one of those occasions where a natural-key makes sense – i.e. use Tag (the varchar) as the primary key, and duplicate it (as a foreign key) in VideoTags – then you don’t need to join to the Tags table all the time.


    If the numbers are larger, it is pretty easy to use SqlBulkCopy; just put the data into a DataTable and push it over, then do the work in TSQL.

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

Sidebar

Ask A Question

Stats

  • Questions 162k
  • Answers 162k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I assume you are using BinaryFormatter? This serializer is notoriously… May 12, 2026 at 11:58 am
  • Editorial Team
    Editorial Team added an answer You can capture the SortCompare event of your datagridview: private… May 12, 2026 at 11:58 am
  • Editorial Team
    Editorial Team added an answer You can't pass an argument to a callable attribute like… May 12, 2026 at 11:58 am

Related Questions

Okay, I have ran in to a problem with VB.NET. So all those defenders
I converted our project from .NET 2.0 to 3.5 and am looking for optimizations
I was writing a generic class to read RSS feed from various source and
I have a database table that has a SortOrder integer column. In the UI

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.