0

In this question the answer also had the option of "Or create a class and return list of that instead of using Anonymous type."

Limit Linq result columns for GridView

Could someone show me how to do that?

1
  • You want someone to show you how to create a class? If you don't know how to do that it is probably best that you do a little more research like read a book on the basics or something. Commented Nov 8, 2011 at 10:14

1 Answer 1

2

anonymous type:

var query = (from dins in h.Dinners
                 where dins.Title == "New York"
                 select new { dins.Title, dins.DinnerID });

custom type:

public class myType
{
public string Title { get; set; }
public int DinnerID { get; set; }
}

select new { etc } 

becomes

select new myType { Title = dins.Title, DinnerID = dins.DinnerID }

You can omit the Title = and DinnerID = IF the property names are the same, but I've included them for clarity

  • This is entirely off the top of my head, I make no assertion that it's compilable/working code for your exact needs!
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.