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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:47:33+00:00 2026-06-17T11:47:33+00:00

I have an EF 5/MVC 4, database first project I am working on and

  • 0

I have an EF 5/MVC 4, database first project I am working on and have created separate edmx files for certain logical functional areas of my application (UserManagement, CompanyManagement, InventoryManagement, OrderManagement). The UserProfile table is in all of the edmx files as it is there to join to the CreatedById and ModifiedById tables so you can get the actual user name. But I don’t want to create additional properties and data annotations in each version of the UserProfile table, so I inherit the (what I call) “original version” of UserProfile which is in the UserManagement area which I add my additional properties and add my data annotations. Ok, still with me?

Ok, so here is the original UserProfile class that EF 5 creates (in the UserManagement area/folder):

namespace OTIS.domain.UserMgmt
{
    using System;
    using System.Collections.Generic;

    public partial class UserProfile
    {
        public UserProfile()
        {
            this.webpages_Roles = new HashSet<webpages_Roles>();
        }

        public int UserId { get; set; }
        public Nullable<int> AccountId { get; set; }
        public string UserName { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Email { get; set; }

        public virtual webpages_Membership webpages_Membership { get; set; }
        public virtual ICollection<webpages_Roles> webpages_Roles { get; set; }
    }
}

Here is my partial class I use to add additional properties and add the data annotations:

namespace OTIS.domain.UserMgmt
{
    [MetadataType(typeof(UserProfileMD))]
    public partial class UserProfile : IEntity
    {
        public int Id
        {
            get
            {
                return this.UserId;
            }
        }

        public string FullName
        {
            get
            {
                return this.FirstName + " " + this.LastName;
            }
        }

        public string EntityDescription
        {
            get
            {
                return this.FullName;
            }
        }

        public class UserProfileMD
        {
            public int UserId { get; set; }

            [Required]
            [Display(Name = "User Name")]
            public string UserName { get; set; }

            [Required]
            [Display(Name = "First Name")]
            public string FirstName { get; set; }

            [Required]
            [Display(Name = "Last Name")]
            public string LastName { get; set; }

            [Display(Name = "Name")]
            public string FullName { get; set; }

            [Display(Name = "Email")]
            public string Email { get; set; }

        }
    }
}

Now I am working with a version of UserProfile that is in the InventoryMgmt edmx, so I created a partial class of the same name and inherited from the above:

namespace OTIS.domain.InventoryMgmt
{
    [MetadataType(typeof(OTIS.domain.UserMgmt.UserProfile.UserProfileMD))]
    public partial class UserProfileInvnMgmt : UserProfile
    {

    }
}

Now also in the InventoryMgmt edmx is PO Header. Here is the EF generated class (note it references UserProfileInvnMgmt UserProfile which is the foreign key table to CreatedById):

namespace OTIS.domain.InventoryMgmt
{
    using System;
    using System.Collections.Generic;

    public partial class POHeader
    {
        public POHeader()
        {
            this.PODetails = new HashSet<PODetail>();
        }

        public int Id { get; set; }
        public int FacilityId { get; set; }
        public int VendorId { get; set; }
        public int StatusId { get; set; }
        public string Notes { get; set; }
        public int CreatedById { get; set; }
        public System.DateTime CreatedOn { get; set; }
        public int ModifiedById { get; set; }
        public System.DateTime ModifiedOn { get; set; }

        public virtual ICollection<PODetail> PODetails { get; set; }
        public virtual Vendor Vendor { get; set; }
        public virtual POHeaderStatus POHeaderStatus { get; set; }
        public virtual UserProfileInvnMgmt UserProfile { get; set; }
        public virtual UserProfileInvnMgmt UserProfile1 { get; set; }
    }
}

Now I have a method that converts a POHeader class entity to a view model. During design time, it allows me to assign POHeader.UserProfile.FullName to the view model property OrderedBy.

public IEnumerable<POHeadersListViewModel> ConvertClassToViewModel(IEnumerable<POHeader> purchaseOrders)
    {
        IEnumerable<POHeadersListViewModel> poGrid =
            from l in purchaseOrders.ToList()
            select new POHeadersListViewModel()
            {
                Id = l.Id,
                VendorName = l.Vendor.VendorName,
                OrderedBy = l.UserProfile.FullName,
                OrderDate = l.CreatedOn,
                Status = l.POHeaderStatus.DisplayName
                //OwnerName = l.Customer == null ? "" : l.Customer.CustomerName
            };

        return poGrid;
    }

HOWEVER, when you run this code, no value gets assigned to OrderedBy AND if, while debugging, expand out the IEnumerable purchaseOrders variable, you see UserProfile, but if you expand it out, you DO NOT see the FullName property, but FirstName and LastName are populated. The resulting value or OrderBy in the view model is a single space, which seems like the FullName property is being returned, but that FirstName and LastName were null, resulting in FullName just returning the white space that is supposed to separate the FirstName and LastName properties, i.e.

public string FullName
    {
        get
        {
            return this.FirstName + " " + this.LastName;
        }
    }

But note that if I do this:

OrderedBy = l.UserProfile.FirstName + " " + l.UserProfile.LastName,

It works, so FirstName and LastName are not null. Any ideas on why FullName is not be returned correctly? In general, is the best way to to handle the multiple versions of UserProfile?

  • 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-17T11:47:34+00:00Added an answer on June 17, 2026 at 11:47 am

    Not sure this is your issue, but your partial class extends IEntity public partial class UserProfile : IEntity where the auto-gen class does not. I believe these should match exactly, or does C# allow you to do that?

    UPDATE I believe you issue is that you are trying the use the derived/calculated property in your linq query, which when you consider mapping this back to your database using EF would not be something it would be able to handle / translate. This discussion seems relevant: Using a partial class property inside LINQ statement

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

Sidebar

Related Questions

I have an ASPNET MVC 3 project made with Entity Framework 4 (database first).
I have an ASP.NET MVC application with the default membership database. I am accessing
I have an embedded database in an asp.net mvc project. If I try to
Here's my situation: I have been working on an ASP.NET MVC 3 application for
I'm currently working on my first MVC project which is nothing more than a
I currently have pagination working in my MVC 3 project using the PagedList library
I have an ASP.NET MVC application where the database is on an IBM i-Series
I have a mvc 3 project and I need to populate sql database with
I have a controller in MVC serving up images from a database. EDIT: This
I'm currently writing a website in ASP.NET MVC, and my database (which doesn't have

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.