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: asp net core cookie authentication, validation in asp net

Post navigation

Next Next post: LINQ to SQL and the XML datatype

Related Posts

  • Microsoft spills the tea on TypeScript

    #​655 — September 21, 2023 Read on the Web JavaScript Weekly ▶  TypeScript Origins: The Documentary — You know you’ve made it when you get your own documentary! This has just dropped but is well produced, packed with stories from TypeScript’s co-creators, users, and other folks at Microsoft, and kept me entertained. It goes particularly deep

    Posted by Posted on September 21, 2023
    0
  • Does Node need a mascot of its own?

    #​502 — September 19, 2023 Read on the Web Does Node.js Need a Mascot? — Go has its cute gopher, Deno has a dinosaur, Bun has, well.. a bun, but what does Node have? Nothing official, as such, and Matteo Collina ponders whether we should change that. Most of the suggestions seem tongue in cheek,

    Posted by Posted on September 19, 2023
    0
  • JavaScript, ML and LLMs

    #​654 — September 14, 2023 Read on the Web JavaScript Weekly Bun 1.0: Is It a Toolkit? Is It a Runtime? It’s Both — You’ve used Node, you’ve seen Deno, now Bun has grown up too. It’s a performance-oriented server-side JS runtime built atop JavaScriptCore and makes the unique claim of being “a drop-in replacement

    Posted by Posted on September 14, 2023
    0
  • You can run GitHub Gists with npx

    #​501 — September 12, 2023 Read on the Web MikroORM 5.8 Released — When MikroORM is mentioned anywhere, I always see folks saying it’s great and deserves more attention, so I’m doing my bit to help 😁 It’s an ORM for Node based around Data Mapper, Unit of Work (hello implicit transactions and change detection!)

    Posted by Posted on September 12, 2023
    0
  • TypeScript 5.2, Node 20.6, and Astro 3.0

    #​653 — September 7, 2023 Read on the Web 😅 We’re back! After two weeks enjoying the blistering desert heat of Las Vegas and downpours of Storm Hilary, I’m ready to get back to the weekly JavaScript roundups – fingers crossed we’re here each week till Christmas now 🙂__Peter Cooper and the Cooperpress team JavaScript Weekly

    Posted by Posted on September 7, 2023
    0
  • Node v20.6.0 released with .env support

    #​500 — September 5, 2023 Read on the Web Node v20.6.0 (Current) Released — As we teased last week, the latest Node release includes all-new built-in support for setting environment variables via .env files, so you may no longer have a need for dotenv, depending on your use case. You can now also use import.meta.resolve

    Posted by Posted on September 5, 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 spills the tea on TypeScript
  • Does Node need a mascot of its own?
  • JavaScript, ML and LLMs
  • You can run GitHub Gists with npx
  • TypeScript 5.2, Node 20.6, and Astro 3.0
https://flatlogic.com/generator
COPYRIGHT © 2023 - Codepolice