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 8562751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:47:56+00:00 2026-06-11T16:47:56+00:00

I am developing an ASP.Net MVC 3 application using Entity Framework 4.1. For a

  • 0

I am developing an ASP.Net MVC 3 application using Entity Framework 4.1. For a particular complex query that I need to execute I have decided to write a raw SQL query and pass it to the built in dbSet.SqlQuery method.

I have a Service method like below where I assign the SQL query to a string variable called query. As the query is passed two parameters, I have parameterized these to prevent SQL Injection.

public IList<User> GetAvailableLocums(int shiftID, int shiftDateID)
{
           var query ="Select .... where t1 = @p0 and t2 = @p1";

           ObjectParameter _shiftID = new ObjectParameter("p0", shiftID);
           ObjectParameter _shiftDateID = new ObjectParameter("p1", shiftDateID);

           object[] parameters = new object[] { _shiftID, _shiftDateID };


           return _UoW.User.GetWithRawSql(query, parameters).ToList();
 }

I then pass the query and the parameters to a method in my repository which executes the query for me.

public IEnumerable<TEntity> GetWithRawSql(string query, params object[] parameters)
{
            return dbSet.SqlQuery(query, parameters).ToList();
}

I know the query is correct as I have tested it in SQL Server Management Studio, however, I currently get the following error when I try to run this code

No mapping exists from object type System.Data.Objects.ObjectParameter
to a known managed provider native type

Does anyone have any suggestions as to how I can fix this?

Thanks for your help.

  • 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-06-11T16:47:57+00:00Added an answer on June 11, 2026 at 4:47 pm

    Folks

    The problem was that I was using ObjectParameter to create my Parameters. I instead changed this to SqlParameter and it worked fine. See below.

    Change from this

    ObjectParameter _shiftID = new ObjectParameter("p0", shiftID);
    

    To this

    SqlParameter _shiftID = new SqlParameter("p0", shiftID);
    

    And it worked. Hope this helps someone else.

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

Sidebar

Related Questions

I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1 and
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1, however,
I am developing a ASP.NET MVC 3 application, i am using entity framework code
I am developing an ASP.Net MVC 3 application using Entity Framework 4.1. For one
I'm developing a web application using ASP.NET MVC 3 and Entity Framework Code First
I am developing an ASP.Net MVC 3 Web application using Entity Framework 4.1. I
I am developing an ASP.Net MVC 3 Web application using Razor Views. I have
I am developing a medium sized ASP.NET project using ASP.NET MVC and Entity Framework.
I'm developing an application using asp.net mvc, NHibernate and DDD. I have a service
I'm developing an web application using asp.net mvc, and i need to do a

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.