Skip to content

Codepolice

  • ⤫

LINQ to SQL and the XML datatype

Posted by Judy Alvarez Posted on February 25, 2022March 3, 2022
0

Today i have done some stuff with LINQ to SQL and the xml data type from SQL Server 2005. I had some problem finding information about this and spent some hours figuring out how the insert/update/delete worked. Post a comment if you find something I’ve done wrong. This is mostly for my own reference.

Get data

var q = (from ec in Business.PostCalc. ExtraCompensation.Descendants("compensation")
select new { id = ec.Attribute("id").Value,
  code = ec.Element("code").Value,
  amount = ec.Element("amount").Value,
  description = ec.Element("description").Value }).ToList();

lwExtraCompensation.DataSource = q;
lwExtraCompensation.DataBind();

Delete data

You should of course run SubmitChanges and so on in some method. I do this way so that we can save everything at once later.

XElement ec = Business.PostCalc.ExtraCompensation;
XElement newExtraComp= new XElement(ec);

newExtraComp.DescendantsAndSelf("compensation")
.Where(x => x.Attribute("id").Value.ToString() == e.CommandArgument.ToString()).First().Remove();

Business.PostCalc.ExtraCompensation = newExtraComp;

txtDescription.Text = "";
txtAmount.Text = "";
txtCode.Text = "";

PostCalculationChanged(this, new EventArgs());

Update data

XElement ec = Business.PostCalc.ExtraCompensation;

XElement newExtraCompensation = new XElement(ec);

newExtraCompensation.Add(new XElement("compensation",
new XElement("description", txtDescription.Text),
new XElement("amount", txtAmount.Text),
new XElement("code", txtCode.Text),
new XAttribute("id", Guid.NewGuid()))
);

Business.PostCalc.ExtraCompensation = newExtraCompensation;

txtDescription.Text = "";
txtAmount.Text = "";
txtCode.Text = "";

PostCalculationChanged(this, new EventArgs());
Categories: JavascriptTagged: .net 5 mvc, .net core vs mvc, .net mvc vs .net core, angular with asp net mvc, asp net core vs mvc, asp net mvc 5 tutorials, asp net mvc architecture, asp net mvc dropdownlist, asp net mvc entity framework, asp net mvc gridview, asp net mvc interview questions for 10 years experience, asp net mvc là gì, asp net mvc page life cycle, asp net mvc partial view, asp net mvc project, asp net mvc projects with source code, asp net mvc shopping cart, asp net mvc tough interview questions, asp net mvc with angularjs, dot net mvc, how to create search box in asp net mvc, learn asp net mvc, microsoft asp net mvc 4 runtime, mvc .net interview questions, mvc architecture in asp net, mvc vs asp net, outsource .net mvc development services, partial view in asp net mvc, session in asp net mvc

Post navigation

Previous Previous post: LINQ to SQL and the XML datatype
Next Next post: ASP.NET 4.0 – Some info from PDC

Related Posts

  • The dog days of JavaScript summer

    #​743 — July 4, 2025 Read on the Web 🖊️ It’s been a quiet week with heatwaves and holidays seeming to slow the usual flow, but we’ve made it.. thanks to a few items out of left field 😅 For our US readers, happy Independence Day!__Peter Cooper, your editor ☀️ JavaScript Weekly ☀️ Deno 2.4:

    Posted by Posted on July 4, 2025
    0
  • Running Gemma 3n from Node

    #​584 — July 1, 2025 Read on the Web Modern Node.js Patterns for 2025 — We’ve reached the half way point for the year, so why not take a moment to reflect on the potential of Node as it stands right now? Ashwin reminds us of various aspects including the use of ES modules, built-in

    Posted by Posted on July 1, 2025
    0
  • Say hello to ECMAScript 2025

    #​742 — June 27, 2025 Read on the Web JavaScript Weekly Ecma International Approves ECMAScript 2025: What’s New? — It’s that time of year again. The Ecma General Assembly has approved the ES2025 language specification, which you can read in full here if you have a gallon of coffee to hand — or you can

    Posted by Posted on June 27, 2025
    0
  • Adonis picks up the pace

    #​583 — June 24, 2025 Read on the Web The Roadmap to AdonisJS 7 — Adonis is a popular TypeScript-first ‘batteries included’ web framework with a rich set of features, and its developers say they’re “shifting gears” and stepping up with more frequent major releases. v7 promises a lot, including Node.js diagnostic channel support, a

    Posted by Posted on June 24, 2025
    0
  • Dr. Axel’s JavaScript flashcards

    #​741 — June 20, 2025 Read on the Web JavaScript Weekly 📖 Exploring JavaScript (ES2025 Edition) — Dr. Axel is back with his latest book covering all things relating to modern JavaScript at the language level (think built-in data types, modularity, how objects, classes and promises work, etc.). As with all of Axel’s books, it’s available

    Posted by Posted on June 20, 2025
    0
  • One step closer to TypeScript

    #​582 — June 17, 2025 Read on the Web Node.js Moves Toward Stable TypeScript Support with Amaro 1.0 — Amaro is Node’s official way to strip types out of TypeScript code so that Node can run it (though you can also use Amaro as a library, if you prefer). The 1.0 release is a key

    Posted by Posted on June 17, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • The dog days of JavaScript summer
  • Running Gemma 3n from Node
  • Say hello to ECMAScript 2025
  • Adonis picks up the pace
  • Dr. Axel’s JavaScript flashcards
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice