BlogEngine.Net 1.XX where have you gone?

Building a Linq Query gives me a question.

3. April 2008 23:12 by scott in   //  Tags: , , ,   //   Comments (17)

So here I am building a new site that will estimate around 500,000 page views and 50,000 database transactions DAILY.  I am currently working on a simple query that selects ONE row[column] from a database and returns the value to the rest of the methods.  I have a simple thought or question I would like answered and thought this would be a place to bring it up.

Is the foreach loop required even if I know I will receive only 1 record back from the database?

That's it and to give you an example:

        CS_Code.DataContext db = new CS_Code.DataContext(SQLStatementsCS.ConnectionStringID());
        var query = from RN in db.Province
                    where RN.Name == Name
                    select RN.uid;

        int value;
        foreach (var uid in query)
        { value = uid; }


I think it is kind of pointless to create a foreach loop and use 3 lines of code to just get an ID out of the database. So let me know in the comments section if this is the only answer and I will point out the answer and give you a link back to a site of your choice.

Thanks guys and dolls.

kick it on DotNetKicks.com

Comments (17) -

VidalSasoon
VidalSasoon
4/7/2008 8:33:26 AM #

Maybe you need "Take"?


weblogs.asp.net/.../...NET-_2800_Part-1_2900_.aspx
====================
       TravelOrganizer travel = new TravelOrganizer();

         GridView1.DataSource = (from location in travel.PlacesVisited
                               orderby location.Distance descending
                               select location).Skip(1).Take(5);
        GridView1.DataBind();

Scott
Scott
4/7/2008 8:41:12 AM #

The problem with that, is I am not using a Girdview and only returning one row and one row only.  So what you just gave me won't help.  Sorry.

Michael Reyeros
Michael Reyeros
4/7/2008 10:24:12 AM #

You could try using the Single Linq operator:
db.Provinces.Single(p => p.Name == Name);

justin
justin
4/7/2008 12:01:38 PM #

int value = (from RN in db.Province
                    where RN.Name == Name
                    select RN.uid).FirstOrDefault();

Scott
Scott
4/19/2008 10:19:50 AM #

Thanks Justin. That works. I appreciate the help guys.

voyance
voyance
7/1/2013 5:13:02 AM #

Tarot divinatoire lapierre denis camel toe  gemeaux astrologie

Look into my blog post ...  voyance - http://www.mavoyancegratuite.biz

tarot amour
tarot amour
7/18/2013 10:04:47 AM #

Horoscope gratuit du jour lion blackjack horoscope haas verseau

my homepage  tarot amour - http://www.bartlatjes.com

Buford
Buford
7/28/2013 4:50:58 AM #

So having enough chicken recipes in the kitchen would be rewarding. When a coating such as bread crumbs are applied to the meat the flavors and coating will cover a greater amount of the meat's surface offering more of these flavors per bite. Copycat recipes from: Applebee's, Kentucky Fried Chicken, Olive Garden, Chili's, Outback Steakhouse, P.

Here is my web blog - fried chicken recipes easy [ Buford - http://www.lombardimeats.com/beefideas.htm ]

www.voyantpartelephone.org
www.voyantpartelephone.org
8/5/2013 9:35:18 AM #

Tirage carte voyance gratuite voyance tarot de marseille gratuit

Also visit my webpage :: voyance gratuite en direct ( www.voyantpartelephone.org - http://www.voyantpartelephone.org )

voyant gratuit
voyant gratuit
8/16/2013 7:28:13 PM #

Tirage tarot gratuit unicorne horoscope chinois ascendant

Also visit my page;  voyant gratuit - http://www.moeys-elibrary.org

voyant gratuit
voyant gratuit
8/17/2013 9:52:46 AM #

Horoscope poisson gratuit tirage tarot gratuit rapide

Also visit my weblog:  voyant gratuit - http://www.agiftforthefuture.org

medium
medium
8/20/2013 1:14:12 AM #

Astrologie calcul ascendant oracle du tarot

My web site  medium - http://www.monvoyant.org

physician assistant program la crosse wi
physician assistant program la crosse wi
8/21/2013 5:57:52 PM #

Hold a practice interview. Compile a list of common interview questions and enlist the help of a trusted friend or family member. Make sure they switch up which questions they ask and the order. With their help, you be confident that you will be prepared for anything the interviewer throws your way.

Take a look at my web blog -  physician assistant program la crosse wi - facemsr.ga2h.com/index.php?do=/profile-1283/info/

jobs in los angeles county
jobs in los angeles county
8/22/2013 5:45:34 AM #

Always review job postings carefully before applying. Pay attention to the desired qualifications, job description and other details in the postings you review. You should avoid applying for jobs you are clearly not qualified for and make sure the documents you submit with your application correspond to the material the employer wants to receive.

my homepage:  jobs in los angeles county - www.snafu.co/.../the-county-jobs-in-los-angeles-c

film x
film x
8/23/2013 1:10:19 AM #

Porno lesbiene woman sex

Here is my page ...  film x - http://www.filmpornoxgratuit.com

voyance gratuite
voyance gratuite
8/24/2013 2:12:11 PM #

Horoscope et tarot du jour gratuit consulter un voyant en ligne gratuitement

Here is my webpage ...  voyance gratuite - http://www.natashasfoodforpaws.com

voyance en ligne gratuite
voyance en ligne gratuite
8/24/2013 4:22:41 PM #

Voyance gratuite claude alexis voyance gratuite une question

Take a look at my webpage;  voyance en ligne gratuite - http://www.foryou-wasserbett.com