Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4017004
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:48:31+00:00 2026-05-20T09:48:31+00:00

I would like a sample of code. At the moment I use linq in

  • 0

I would like a sample of code.
At the moment I use linq in c# and asp.net 4 ef4

       var querySlotOrder = from slot in context.CmsSlots
                             where slot.SlotId == myCurrentSlotId
                             select slot;

           if (querySlotOrder.SlotOrder == myNewSlotOrder)
                e.Cancel = true;

This linq query return only a record.

Using VAR I cannot get the Typed Object and I cannot access its property SlotOrder.

How to change the query? thanks for your help

Usefully resource on the topic:

http://msdn.microsoft.com/en-us/library/bb384065.aspx

http://msdn.microsoft.com/en-us/library/bb397947.aspx

http://msdn.microsoft.com/en-us/library/bb397678.aspx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:48:32+00:00Added an answer on May 20, 2026 at 9:48 am

    Even if your query returns a single object, the Select method, which you are using behind the scenes, doesn’t. It returns an IQueryable<T> in EF.

    You should use a method such as Single, SingleOrDefault, First, FirstOrDefault if you want to store a single object.

    var querySlotOrder = (from slot in context.CmsSlots
                          where slot.SlotId == myCurrentSlotId
                          select slot).Single();
    

    The difference between the four methods is:

    • Single: Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
    • SingleOrDefault: Returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
    • First: Returns the first element of a sequence.
    • FirstOrDefault: Returns the first element of a sequence, or a default value if the sequence contains no elements.

    (Definitions from MSDN)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some asp.net pagination code samples. I would like suggestions on open source
I use asp.net and C# 4. I would like to know if is possible
I would like a code sample for a function that takes a tDateTime and
I would like to extract items from this sample html, more specificly, i would
HI all, I would like to call from my C# code, unamanaged library functions
Using the Northwind sample: I would like to create an insert trigger on the
I would like to be able to switch this... My sample [a id=keyword href=someURLkeyword]
I'm trying to draw a simple line graph which would use values from the
I would like to understand how socket work, especially I need some code samples
I'm would like some advice on the best data persistence solution to use for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.