2

I m just starting with microsoft (MVC,C#, LINQ), so far so good, but i have a question about LINQ uses, How do i get the value form a LINQ like this one?

            var x = from a in db.tablex
                    where a.eventID == eventID
                    select new
                    {
                       owner = a.owner,
                        shipper = a.shipper,
                        consignee = a.consignee
                    };

I try something like "r.owner" inside a foreach to get the value retrieved from DB

foreach (var r in x)

but its not working.. i dont get intellisense either.. how do i get the value??. I saw several examples and it seems to work like this, but for some reason its not working.. Thanks

0

2 Answers 2

1

Ok guys here was the thing, (it wasnt the typo it was just in the post), i was missing a using :

using System.Reflection; 

with this C# automatically creates a class from them, and now it works

What a noob of me =).

Sign up to request clarification or add additional context in comments.

Comments

0
foreach (var r in x)
{
 var owner = r.owner;// not x.owner
}

1 Comment

introducing a again is probably only going to add confusion... "var owner = r.owner;" would probably be clearer...

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.