HighTechTalks DotNet Forums  

problem with var in 3.5

Dotnet Framework microsoft.public.dotnet.framework


Discuss problem with var in 3.5 in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
dan
 
Posts: n/a

Default problem with var in 3.5 - 11-25-2007 , 03:52 PM







Hello,
i don't know whether you can answer to questions about issues in 3.5, but
i'll ask anyway.
i have this code:

var material = from materials in myDC.Materials
where materials.Name == materialName
select materials;

it is supposed to load 1 object.
how do i know if "material" is loaded or is null or smth like this?
or should i use foreach every time? because in this case, material is
IQueriable<Material>.

or i can write an extension method, but i have to write this for all my
domain objects...
so, how can i do it in a simpler way?

Thank you,
Dan




Reply With Quote
  #2  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: problem with var in 3.5 - 11-25-2007 , 04:10 PM






dan <d@d.d> wrote:
Quote:
i don't know whether you can answer to questions about issues in 3.5, but
i'll ask anyway.
i have this code:

var material = from materials in myDC.Materials
where materials.Name == materialName
select materials;

it is supposed to load 1 object.

how do i know if "material" is loaded or is null or smth like this?
or should i use foreach every time? because in this case, material is
IQueriable<Material>.
Options are:

FirstOrDefault() - there might be 0 or 1 matches
First() - there might be more than one match, just use the first
Single() - there should be exactly one match, throw otherwise

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Reply With Quote
  #3  
Old   
dan
 
Posts: n/a

Default Re: problem with var in 3.5 - 11-26-2007 , 12:29 PM




"Jon Skeet [C# MVP]" <skeet (AT) pobox (DOT) com> wrote

Quote:
dan <d@d.d> wrote:
i don't know whether you can answer to questions about issues in 3.5, but
i'll ask anyway.
i have this code:

var material = from materials in myDC.Materials
where materials.Name == materialName
select materials;

it is supposed to load 1 object.

how do i know if "material" is loaded or is null or smth like this?
or should i use foreach every time? because in this case, material is
IQueriable<Material>.

Options are:

FirstOrDefault() - there might be 0 or 1 matches
First() - there might be more than one match, just use the first
Single() - there should be exactly one match, throw otherwise
Thank you!

I used also
material.Count<Material>() < 1

Dan




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.