vb.net - I have a Tags Table. How to Bulk Insert using LINQ? -


I am using VB.NET with LINQ from MS SQL. I have two following tables, now I want to add multiple items in the tag table using LINQ, but also want to see that any tags in the tag table are present. It does not reinclude it, and in both cases, the tag is inserted (if it has been inserted or if it exists)

  created tab tags (tag wide built tap, tags Vertical (100) null) Videotag (Videind Blinkt is not empty, TagImit bilint is not empty)  

What is the best way to use LINQ?

In advance thanks

LINQ is an query technique , But I think we know what you mean; You want to be a bit more specific whether it is LINQ-to-SQL or Entity Framework. You can also clarify what the "bulk" means in your case ... For 10-100 records, you have 10,000 records (Where it would be best to import a staging table in SqlBulkCopy and an Archived Functional DB).

For a relatively small number - just use your ORM tool to find the record - for example LINQ-to-SQL (probably spreading serialized transaction) - and for illustration # of C # Experiment ( has been updated to show loops and cache ):

  dictionary & lt; String, tag & gt; Known tags = new dictionary & lt; String, tag & gt; (); Foreign currency (... your data ...) {tag tag; If (known! Tags.TryGetValue (tag name, tag outside)) {tag = ctx.Tags.SingleOrDefault (t = & gt; t.Name == tagName); If (tag == zero) {tag = new tag {name = tagname}; Ctx.Tags.InsertOnSubmit (tag); } KnownTags.Add (tagname, tag); } // Insert Video Tag} ctx.SubmitChanges (); In fact, due to the performance reasons, I wonder if it can be one of those occasions where a natural-key is understood - i.e. use  tag  ( varchar) < / Code>) as a primary key, and duplicate it (as a foreign key) in  VideoTags  - then you do not need to be included in the  tag  table. . 


If the number is large, then using SqlBulkCopy is very easy; Just insert the data into a DataTable and press it, then work in TSQL.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -