Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 155727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:12:24+00:00 2026-05-11T10:12:24+00:00

I have this fragment of code: SmsDataClassesDataContext dc = new SmsDataClassesDataContext(); // Get the

  • 0

I have this fragment of code:

SmsDataClassesDataContext dc = new SmsDataClassesDataContext();          // Get the customer         Customer currentCustomer = dc.Customers.Single( c => c.Hash1 == forThisHash );           // Get from Name (LINQ to XML)          var q = from c in thisSmsPack.Descendants('from')                 select c;          string from = q.First().Value;          foreach ( XElement element in thisSmsPack.Descendants('to') )         {             // Create the queue             SmsQueue sq = new SmsQueue();             sq.CustomerId = currentCustomer.CustomerId;             sq.MsgFrom = from;              sq.MsgTo = element.Attribute('name').Value;             sq.MsgPhone = element.Attribute('phone').Value;             sq.MsgBody = element.Attribute('msg').Value;             sq.Priority = currentCustomer.SendsSmsAtPriority;             sq.DontSendUntil = GetNextSendDate();               // sq.TimeCreated = System.DateTime.Now;              currentCustomer.SmsQueues.Add(sq);         }         dc.SubmitChanges(); 

I am creating new instances of ‘SmsQueues’, populating the values and when the foreach loop is finished I submit the changes. Given the new lambda/linq/anonymous types that .NET 3.5 has, is there a more ‘modern’ way to accomplish the above?

As a side question, maybe related, can I return an existing type composed of different columns in the select part of the linq expression?

Suppose you have three tables:

T1 == T1.Id, T1.Name

T2 == T2.Id, T2.Phone

T3 == T3.Name, T3.Phone, T3.SomethingElse

Can I perform a LINQ query that returns:

T1.Name, T2.Phone, SomethingElseNew

And let .NET know that that is of Type T3 (and it’s a new instance of it)? That way when I SubmitChanges, new T3 instances are inserted in the DB?

I don’t know if I make myself clear :S

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:12:25+00:00Added an answer on May 11, 2026 at 10:12 am

    I don’t have a system available to test this, but I think this (or something very close) should work.

    CustomerId = currentCustomer.CustomerId; var sqrange = from element in thisSmsPack.Descendants('to') )               select new SmsQueue               {              // Create the queue                 MsgFrom = from,                 MsgTo = element.Attribute('name').Value,                 MsgPhone = element.Attribute('phone').Value,                 MsgBody = element.Attribute('msg').Value,                 Priority = currentCustomer.SendsSmsAtPriority,                 DontSendUntil = GetNextSendDate()              // TimeCreated = System.DateTime.Now             };     currentCustomer.SmsQueues.AddRange(sqrange); 

    EDIT: Fixed the numerous syntax errors (as delineated in the comments)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 140k
  • Answers 140k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you can use sms.dll library to manipulate SMS in Windows… May 12, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer You should be passing a strongly typed form or interface… May 12, 2026 at 7:57 am
  • Editorial Team
    Editorial Team added an answer The internal error handling of the framework's MVC components can… May 12, 2026 at 7:57 am

Related Questions

In Javascript, I have this function to display the current date on our page
I have the following (fairly) simple JavaScript snippet that I have wired into Greasemonkey.
I currently represent my Business Layer and Data Layer in a single project in
In this code fragment foreach (var row in grid.Rows) { } the type of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.