Solved

Linq cast a table as a custom class

Posted on 2013-11-14
1
232 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
[X]
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
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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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