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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:08+00:00 2026-05-23T10:44:08+00:00

I have created an entity framework 4.0 (DB-First) model, added my partial classes and

  • 0

I have created an entity framework 4.0 (DB-First) model, added my partial classes and used DataAnnotations on them to have a perfect UI on the client.

I have some relations between my tables and used DisplayColumn on top my classes. e.g. I have a User class that has [DataColumn("UserName")] attribute on top of the class. And a Message class which has “public User Sender” which has [Include] attribute on top of the property.

Also, I have used .Include("User") in my DomainService to load the User who’s related to a message.

But in my datagrid, I see User : (UserID) (UserID=Key property of User entity) instead of UserName that I have specified. I looked in the generated code in my SL project and it correctly decorated my User class with DisplayColumn attribute. But still, I cannot see UserName in my grid.

Any help would be greatly appreciated.
Update: Here’s my question in code:

As I have mentioned, Owner, UserName, MessageId, UserId have been defined in my auto-generated model. UserMeta class has nothing special.

[MetadataType(typeof(MessageMeta))]
public partial class Message
{
}  

public class MessageMeta
{
 [Include()]
 [Display(Name = "Belongs to", Order = 4)]
 [Association("Message_User","MessageId","UserId",IsForeignKey =  true)]
 public virtual User Owner { get; set; }
}

[MetadataType(typeof(UserMeta))]
[DisplayColumn("UserName")]
public partial class User
{
}  

In my DomainService:

public IQueryable<Message> GetMessages()
{
    return this.ObjectContext.Messages.Include("Owner");
}
  • 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-23T10:44:09+00:00Added an answer on May 23, 2026 at 10:44 am

    At last, I had to use Reflection. For DataGrid:

    private void OnAutoGenerateColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
        {
            //Need to get an array, but should always just have a single DisplayColumnAttribute
            var atts = e.PropertyType.GetCustomAttributes(typeof(DisplayColumnAttribute),true);
    
            foreach (DisplayColumnAttribute d in atts)
            {
                DataGridTextColumn col = (DataGridTextColumn)e.Column;
    
                //Make sure that we always have the base path
                if(col.Binding.Path.Path!="")
                {
                    col.Binding = new Binding()
                    {
                        Path = new PropertyPath(col.Binding.Path.Path + "." + d.DisplayColumn)
                    };
                }
    
                //Only do the first one, just in case we have more than one in metadata
                break;
            }
    
        } 
    

    And for Telerik RadGridView:

    var column = e.Column as GridViewDataColumn;
    if (column == null)
    {
        return;
    }
    
    // Need to get an array, but should always just have a single DisplayColumnAttribute  
    var atts = column.DataType.GetCustomAttributes(typeof(DisplayColumnAttribute), true);
    
    foreach (DisplayColumnAttribute d in atts)
    {
        // Make sure that we always have the base path
        if (column.DataMemberBinding.Path.Path != "")
        {
            column.DataMemberBinding = new Binding()
            {
                Path = new PropertyPath(column.DataMemberBinding.Path.Path + "." + d.DisplayColumn)
            };
         }
         // Only do the first one, just in case we have more than one in metadata
         break;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Dynamic Data site against an Entity Framework Model I have
I have an Entity Framework 4 model-first design. I create a first draft of
In my application I'm using Entity Framework 4.0 Model First. I have several tables
I am getting started with the ADO.NET Entity Framework 4.0. I have created an
I have an Entity Data Model that I have created, and its pulling in
In this code, I have an Entity Framework 4 model with a single Thing
I have a small MVC 3 app using Entity Framework Code First and use
This is my first WinForm application using the Entity Framework and I have to
Application uses Entity Framework 4.1 with database first approach. I have in database a
I Am creating a web application and first use Entity Framework. I created Entity

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.