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

  • A new guide to configuring Node packages

    #​607 — January 15, 2026 Read on the Web ⚠️ The Node.js January 13, 2026 Security Releases — Originally expected in December, these releases (of Node.js 25.3.0, 24.13.0, 22.22.0, and 20.20.0) finally landed this week, largely due to their complexity and the scope of the vulnerabilities they tackle. More on that in the next item! The Node.js

    Posted by Posted on January 15, 2026
    0
  • Can we ever fix the web dependency mess?

    #​768 — January 13, 2026 Read on the Web JavaScript Weekly Web Dependencies are Broken; Can We Fix Them? — Lea, who has worked at the heart of Web Standards for years, delivers a compelling (and educational) call to action about a problem every JavaScript developer has encountered: why is managing dependencies and introducing them

    Posted by Posted on January 13, 2026
    0
  • The story of how require(esm) became stable

    #​606 — January 8, 2026 Read on the Web 🎉 Happy New Year! Also, a quick reminder that Node Weekly is now sent every Thursday as part of a reshuffle for many of our newsletters. __Your editor, Peter Cooper npm to Implement ‘Staged Publishing’ After Turbulent Shift Off Classic Tokens — 2025 was a tricky year

    Posted by Posted on January 8, 2026
    0
  • A new JavaScript engine from Fabrice Bellard

    #​767 — January 6, 2026 Read on the Web 🎉 Happy New Year. JavaScript Weekly is now landing in your inboxes on Tuesdays, so here we are! Let’s see what 2026 brings.__Your editor, Peter Cooper JavaScript Weekly The 2025 JavaScript Rising Stars — At the start of each year, Michael rounds up the projects in the

    Posted by Posted on January 6, 2026
    0
  • The JavaScript Bundler Grand Prix

    #​766 — December 19, 2025 Read on the Web 🗓️ As it’s the last issue of 2025, a reminder that JavaScript Weekly moves to Tuesdays in January. See you again on January 6, 2026!__Your editor, Peter Cooper JavaScript Weekly It’s the final issue of the year, so we’re going to cover a few new items, then

    Posted by Posted on December 19, 2025
    0
  • ‘Twas the Node before Christmas…

    #​605 — December 16, 2025 Read on the Web 🗓️ Today we’re taking a look back over some of the big stories and links that got you clicking this year. Also, Node Weekly will be moving to Thursdays in January 2026, as part of a reshuffle for many of our newsletters. __Your editor, Peter Cooper This

    Posted by Posted on December 16, 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
  • A new guide to configuring Node packages
  • Can we ever fix the web dependency mess?
  • The story of how require(esm) became stable
  • A new JavaScript engine from Fabrice Bellard
  • The JavaScript Bundler Grand Prix
https://flatlogic.com/generator
COPYRIGHT © 2026 - Codepolice