Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Linq cast a table as a custom class

Posted on 2013-11-14
1
230 Views
Last Modified: 2016-02-10
I created a class that matches a database table that I have in SQL. How can cast my var as this new custom class.

Person C = (from x in ctx1.Persons where x.PersonID == RecID select x).FirstOrDefault();
I want to dump this into a custom class name PersonInfo.
0
Comment
Question by:NickMalloy
1 Comment
 
LVL 21

Accepted Solution

by:
Craig Wagner earned 350 total points
ID: 39649857
Person C = from x in ctx1.Persons
             where x.PersonID == RecID
             select new PersonInfo()
             {
                 PersonID = x.PersonID,
                 PersonName = x.PersonName,
                 // etc
              }
             .FirstOrDefault();

Open in new window

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question