Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • Don't you mean: string name = item.ProductName; int id = item.ProductId; Commented Jan 29, 2010 at 16:17
  • I use the same method for a lot of Tables, thats why i dont use strongly typed result. So, i have to cast every time, not?. Thanks Commented Jan 29, 2010 at 17:19
  • @Mark yes, in that case you would need to cast as you were doing. If your SELECT statement is always going to represent an ORM_Linq.Articu object then you might as well make it IQueryable<ORM_Linq.Articu>. Nonetheless, you should follow the approach demonstrated above to capture the result using SingleOrDefault() to handle it correctly in case the result is null. Commented Jan 29, 2010 at 17:23
  • Thank you and everybody. Is really hard after 5 years working on Visual FoxPro learn how to work on C# and SQL :( Commented Jan 29, 2010 at 17:40
  • 1
    @Mark if you haven't already then I suggest getting your hands on a good LINQ book. C#/SQL is one thing, LINQ to SQL is different than traditional ADO.NET using a SqlConnection. I recommend LINQ in Action by Fabrice Marguerie, Steve Eichert and Jim Wooley available here: manning.com/marguerie For C# I suggest Pro C# 2008 and the .NET 3.5 Platform (apress.com/book/view/1590598849) or C# 3.0 in a Nutshell (oreilly.com/catalog/9780596527570) - both these books have new 4.0 editions being released soon. Commented Jan 29, 2010 at 18:33