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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:37:23+00:00 2026-05-20T21:37:23+00:00

Greetings! I’m using SPROCs within Entity Framework for all of my CRUD methods. Because

  • 0

Greetings!

I’m using SPROCs within Entity Framework for all of my CRUD methods. Because this is a multi-tenant database, we have a clientID field in each of the tables. Our DBA doesn’t want that clientID exposed, so we pass a username into the SPROC (username of authenticated user, tracked in the membership provider), which then handles conversion of username to clientID internally within sproc.

The issue I’m having is that my Entities don’t have the Username property. When I create my function imports for insert/update/delete, the mapping is requesting a Username field (required, from my SPROC) which doesn’t exist in my entity. Here’s my schema:

Account Entity

AccountNumber
AccountDescription
ClientID
ActiveFlag
RowVersion (for concurrency)

And my SPROC:

ALTER PROCEDURE [dbo].[GetAccounts]
@Username   varchar (60)
AS

/*********************************************
Summary:  Get Accounts
2011-01-20 aca  initial version
2011-01-27 aca  Alias for Description
2011-03-21 aca  Implement user security
********************************************/
select  P.FERC_ACCOUNT,
    P.[DESCRIPTION] as AccountDescription,
    P.RowVersion
from    dbo.P_ACCOUNTS P
join    dbo.v_UserClient U
on  U.Username = @Username
and P.CLIENT_ID = U.Client_ID
where   P.ActiveFlag = 1;

RETURN 0;

I’m not sure what the best way to proceed is. Do I just create a Username property in my entity? That means I’d have to do this on every one? How do I populate it? Etc etc 🙂

Thanks for your help!

Scott

  • 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-20T21:37:24+00:00Added an answer on May 20, 2026 at 9:37 pm

    I have the same restrictions and I export the stored procedures as functions. For procedures that do not have output parameters I return the default generated complex type i.e. GetAccountsResult.

    public IEnumerable<GetAccountsResult> GetAccounts(string username)
    {
        return ObjectContext.GetAccounts(username).AsQueryable();
    }
    

    The complex type needs to have a property designated as the [Key]. To set the key for complextypes I create a partial for my domain service and use a buddy class to set the key. So for AccountsDomainService.cs I create AccountsDomainService.metadata.cs.

    [MetadataType(typeof(GetAccountsResultMetadata))]
        public partial class GetAccountsResult
    {
        internal sealed class GetAccountsResultMetadata
        {
            [Key]
            public int Id { get; set; }
        }
    }
    

    For procedures that do have output parameters I create a poco object containing properties for the output parameters and another poco object matching the complex type. I then use AutoMapper to map the returned complex type to my created complex type. I do this so I can return the relation.

    Account.cs

     public class Account
        {
            [Key]
            public int Id { get; set; }
            public string MyOutputParameter { get; set; }
    
            [Include, Association("Account_AccountDetails", "Id", "AccountId")]
            public List<AccountDetail> AccountDetails { get; set; }
        }
    

    AccountDetail.cs

        public class AccountDetail
        {
            [Key]
            public int Id { get; set; }
            public int AccountId { get; set; }
            public string MyAccountDetailProperty { get; set; }
        }
    

    AccountDomainService.cs

     public Account GetAccountsWithOutputParms(string username)
            {
                var myOutputParameter = new ObjectParameter("MyOutPutParameter", typeof(int));
    
                var tempGetAccountsResult = ObjectContext.GetAccounts(username).ToList();
    
                var account = new Account
                                  {
                                      Id = 1,
                                      MyOutputParameter = myOutputParameter,
                                      AccountDetails = Mapper.Map<List<GetAccountsResult>, List<AccountDetail>>(tempGetAccountsResult)
                                  };
    
                return accout;
            }
    

    When I get those results on the client, I use AutoMapper to map them to client side view models.

    This article Stored Procedures with EF 4 and RIA Services is handy.

    For insert/update you can create a poco object that models the procedure parameters and pass it to your exported function in your domain service.

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

Sidebar

Related Questions

Greetings all, I'm trying to localize a .NET/C# project. I'm using string resource files
Greetings All, I need to optimize a RegEx I am using to parse template
Greetings! I am trying to check directory write-permissions from within a Windows MFC/ATL program
greetings all i have a domain class named car and i have an object
Greetings, In an WPF DataGridTemplateColumn I have a CellTemplate using a ListView and a
Greetings Everyone I am new in asp.net and i'm using RadControls for Asp.net Ajax
Greetings, this is my very first question and I just do programming as a
Greetings all, Is there any widget to separate two QWidgets and also give full
Greetings all Currently working on assessing a project, and wondered if there was a
Greetings all, I've been told by co-workers that the GET method is different in

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.