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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:18+00:00 2026-06-05T07:09:18+00:00

Using Entity Framework I can create concrete classes from most of the sprocs in

  • 0

Using Entity Framework I can create concrete classes from most of the sprocs in the database of a project I’m working on. However, some of the sprocs use dynamic SQL and as such no metadata is returned for the sproc.

So for a that sproc, I manually created a concrete class and now want to map the sproc output to this class and return a list of this type.

Using the following method I can get a collection of objects:

                var results = connection.Query<object>("get_buddies", 
                    new {   RecsPerPage = 100,
                            RecCount = 0,
                            PageNumber = 0,
                            OrderBy = "LastestLogin",
                            ProfileID = profileID,
                            ASC = 1}, 
                        commandType: CommandType.StoredProcedure);

My concrete class contains

[DataContractAttribute(IsReference=true)]
[Serializable()]
public partial class LoggedInMember : ComplexObject
{

   /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.Int16 RowID
    {
        get
        {
            return _RowID;
        }
        set
        {
            OnRowIDChanging(value);
            ReportPropertyChanging("RowID");
            _RowID = StructuralObject.SetValidValue(value);
            ReportPropertyChanged("RowID");
            OnRowIDChanged();
        }
    }
    private global::System.Int16 _RowID;
    partial void OnRowIDChanging(global::System.Int16 value);
    partial void OnRowIDChanged();

    [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
    [DataMemberAttribute()]
    public global::System.String NickName
    {
        get
        {
            return _NickName;
        }
        set
        {
            OnNickNameChanging(value);
            ReportPropertyChanging("NickName");
            _NickName = StructuralObject.SetValidValue(value, false);
            ReportPropertyChanged("NickName");
            OnNickNameChanged();
        }
    }
    private global::System.String _NickName;
    partial void OnNickNameChanging(global::System.String value);
    partial void OnNickNameChanged();
    .
    .
    .

Without having to iterate through the results and add the output parameters to the LoggedInMember object, how do I map these on the fly so I can return a list of them through a WCF service?

If I try var results = connection.Query<LoggedInMember>("sq_mobile_get_buddies_v35", ... I get the following error:

System.Data.DataException: Error parsing column 0 (RowID=1 – Int64)
—> System.InvalidCastException: Specified cast is not valid. at Deserialize…

  • 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-05T07:09:19+00:00Added an answer on June 5, 2026 at 7:09 am

    The solution to this was to create a complex object derived from the sproc with EF:

        public ProfileDetailsByID_Result GetAllProfileDetailsByID(int profileID)
        {
            using (IDbConnection connection = OpenConnection("PrimaryDBConnectionString"))
            {
                try
                {
                    var profile = connection.Query<ProfileDetailsByID_Result>("sproc_profile_get_by_id",
                        new { profileid = profileID },
                        commandType: CommandType.StoredProcedure).FirstOrDefault();
    
                    return profile;
                }
                catch (Exception ex)
                {
                    ErrorLogging.Instance.Fatal(ex);        // use singleton for logging
                    return null;
                }
            }
        }
    

    In this case, ProfileDetailsByID_Result is the object that I manually created using Entity Framework through the Complex Type creation process (right-click on the model diagram, select Add/Complex Type…, or use the Complex Types tree on the RHS).

    A WORD OF CAUTION

    Because this object’s properties are derived from the sproc, EF has no way of knowing if a property is nullable. For any nullable property types, you must manually configure these by selecting the property and setting its it’s Nullable property to true.

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

Sidebar

Related Questions

I am using the Entity Framework just to create classes that can be mapped
I'm creating a database using entity framework code first and I'm having some issues
I am trying to create WCF Data service project using Entity Framework. ( I
I started using Entity Framework (Using POCO Classes) for a MVC 3 C# project
I have an issue with the project I'm working on. I'm using Entity Framework.
Trying to map the following schema using the Entity Framework. A Customer can have
Can anyone help? I have been using the entity framework and its going well
I'm using Entity Framework in my project, and I have the problem that, once
I'm using entity framework to connect with the database. I've one little problem: I've
I am successfully creating database (SQL Ce) using Entity Framework Code First approach (C#-WPF).

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.