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

  • SEARCH
  • Home
  • 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 7615079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:34:01+00:00 2026-05-31T02:34:01+00:00

In Entity Framework 4, I’m facing a problem when I use function import to

  • 0

In Entity Framework 4, I’m facing a problem when I use function import to a stored procedure and then using as a scalar value. It generates the code below:

public virtual ObjectResult<Nullable<int>> GetTopEmployee()
{
    return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<Nullable<int>("GetTopEmployee");
}

How do I use the return value of this method?

For example, this code works fine:

NorthwindEntities db = new NorthwindEntities();
var i = db.GetTopEmployee();

But I want to use return values only as int. If I use return value as non while in function import it give -1 as output.

When I try the code below:

NorthwindEntities db2 = new NorthwindEntities();
int j = db.GetTopEmployee();

It throws an error saying:

Cannot implicitly convert type ‘System.Data.Objects.ObjectResult’ to ‘int’

How do I parse the above?

  • 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-31T02:34:02+00:00Added an answer on May 31, 2026 at 2:34 am

    Notice that the return type of GetTopEmployee is an ObjectResult<Nullable<int>>. ObjectResult<T> implements IEnumerable<T> so your method is capable of returning more than one Nullable<int>.

    I assume you are trying to get some form of Id for the employee. If you are absolutely sure you are only going to get one result you could use the following code to get that Id.

      var topId = db.GetTopEmployee().FirstOrDefault();
    

    topId could be null. You will have to use topId.Value or var result = topId ?? -1; to get an int result.

      NorthwindEntities db = new NorthwindEntities();
      int j = db.GetTopEmployee().FirstOrDefault() ?? -1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Entity framework is cripplingly slow so I tried using a stored procedure but I
From Entity Framework using ASP .NET MVC 3.0, is it possible to use a
Entity Framework with POCO Entities generated by T4 template. Added Function Import named it
Using Entity Framework, I suddenly get this strange error after publishing my asp.net mvc
(USING ENTITY FRAMEWORK 4.3 CODE FIRST) The code is below. I want to actually
I'm using Entity Framework O/R mapper from Microsoft and using entity classes (generated classes
When using the Entity Framework, does ESQL perform better than Linq to Entities? I'd
Using Entity Framework 4.1 code first and POCO entities in MVC3; I would like
Using Entity Framework. Simple Page class with tree hierarchy. public class Page { public
In Entity Framework 4, what is the difference between Lazy Loading, and using Load()

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.