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

  • Microsoft shrunk the TypeScript

    #​640 — May 25, 2023 Read on the Web JavaScript Weekly DeviceScript: TypeScript for Tiny Thingamabobs — DeviceScript is a new Microsoft effort to take the TypeScript experience to low-resource microcontroller-based devices. It’s compiled to a custom VM bytecode which can run in such constrained environments. (A bit like Go’s TinyGo.) It’s aimed at VS

    Posted by Posted on May 25, 2023
    0
  • Node.js 20 is fast(er)

    #​487 — May 23, 2023 Read on the Web The State of Node.js Performance in 2023 — Nearform’s Rafael Gonzaga reflects on the recent release of Node 20 and puts it through its paces against v18.16 and v16.20 with a few different benchmark suites running on a pretty typical EC2 instance. It goes into a

    Posted by Posted on May 23, 2023
    0
  • jQuery lives on; major changes teased

    #​639 — May 18, 2023 Read on the Web JavaScript Weekly Bun’s New Bundler: 220x Faster than webpack? — Bun is one of the newest JavaScript runtimes (built atop the JavaScriptCore engine) and focuses on speed while aiming to be a drop-in replacement for Node.js. This week’s v0.6.0 release is the ‘biggest release yet’ with

    Posted by Posted on May 18, 2023
    0
  • MS’s new tool for digging deep into V8

    #​486 — May 16, 2023 Read on the Web ‘This Page is Hosted on my Android Phone’ — Since it’s been linked on some pretty big sites already, I don’t feel too guilty about linking it here too 😆 This is a link to a blog being hosted from a $180 Android phone that’s running

    Posted by Posted on May 16, 2023
    0
  • Why Svelte is converting TypeScript to JSDoc

    #​638 — May 11, 2023 Read on the Web JavaScript Weekly The JavaScript Ecosystem is Delightfully Weird — There are plenty of examples of how JavaScript is weird but Sam focuses on the why. If you’ve been a JS developer for many years you’ll have seen it go through many phases and morph to fit

    Posted by Posted on May 11, 2023
    0
  • Getting recursive with Node 20.1

    #​485 — May 9, 2023 Read on the Web Node v20.1.0 (Current) Released — If you’re still catching your breath after the epic Node 20 release, don’t fear – 20.1 is a more typical bugfix, dependency update, and tweak-style affair. Michaël Zasso 💡 That said, the fs readdir and opendir functions get a new recursive option

    Posted by Posted on May 9, 2023
    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
  • Microsoft shrunk the TypeScript
  • Node.js 20 is fast(er)
  • jQuery lives on; major changes teased
  • MS’s new tool for digging deep into V8
  • Why Svelte is converting TypeScript to JSDoc
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice