Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom Properties in partial class of Entities Framework object not displayed in ASP.NET Dynamic Data

Custom Properties in partial class of Entities Framework object not displayed in ASP.NET Dynamic Data

Scheduled Pinned Locked Moved ASP.NET
databasecsharptutorialasp-netlinq
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kris Penner
    wrote on last edited by
    #1

    Hello, I am trying to display in a Dynamic Data app, a custom property added to the partial class of an ADO.NET Entity Framework entity class. For example, where Person is a entity in a ADO.NET Entity Framework model, I would add:

    public partial class Person
    {
    public string FullName { get { return FirstName + " " + LastName; } }
    }

    However, with Dynamic Data, it uses the internal System.Web.DynamicData.ModelProviders.EFTableProvider for generating its columns collection which only allows properties defined in the entity model to be displayed - as in only the database columns, not custom added ones. Does anyone know any work arounds to this, or is it possible and I am missing something obvious. Seems silly I can't do this. LINQ to SQL with Dynamic Data can do this easy as it uses reflection in its DLinqTableProvider to find all properties in the object, not just those with mappings to database fields. EFTableProvider's enumerator to create its columns for Dynamic Data: foreach (EdmMember member in entityType.get_Members()) // only entity DB mapped fields are returned in the Members property DLinqTableProvider's enumerator to create its columns for Dynamic Data: IEnumerator<PropertyInfo> enumerator = this.GetOrderedProperties(rowType.get_Type()).GetEnumerator() where GetOrderedProperties returns a list of properties based on reflection: PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); Anyone have any thoughts on how to do this effectively? I need the many-to-many relationship management that Entity Framework provides - otherwise I would stick with LINQ to SQL. Thanks for any help! Cheers, kris

    B M 2 Replies Last reply
    0
    • K Kris Penner

      Hello, I am trying to display in a Dynamic Data app, a custom property added to the partial class of an ADO.NET Entity Framework entity class. For example, where Person is a entity in a ADO.NET Entity Framework model, I would add:

      public partial class Person
      {
      public string FullName { get { return FirstName + " " + LastName; } }
      }

      However, with Dynamic Data, it uses the internal System.Web.DynamicData.ModelProviders.EFTableProvider for generating its columns collection which only allows properties defined in the entity model to be displayed - as in only the database columns, not custom added ones. Does anyone know any work arounds to this, or is it possible and I am missing something obvious. Seems silly I can't do this. LINQ to SQL with Dynamic Data can do this easy as it uses reflection in its DLinqTableProvider to find all properties in the object, not just those with mappings to database fields. EFTableProvider's enumerator to create its columns for Dynamic Data: foreach (EdmMember member in entityType.get_Members()) // only entity DB mapped fields are returned in the Members property DLinqTableProvider's enumerator to create its columns for Dynamic Data: IEnumerator<PropertyInfo> enumerator = this.GetOrderedProperties(rowType.get_Type()).GetEnumerator() where GetOrderedProperties returns a list of properties based on reflection: PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); Anyone have any thoughts on how to do this effectively? I need the many-to-many relationship management that Entity Framework provides - otherwise I would stick with LINQ to SQL. Thanks for any help! Cheers, kris

      B Offline
      B Offline
      Brady Kelly
      wrote on last edited by
      #2

      Why are you adding the custom property? If it is to use in the DisplayColumn metadata attribute, you can override ToString on your entity to return the full name, and remove the DisplayColumn attribute, and the ToString value will be used instead for FK displays.

      B 1 Reply Last reply
      0
      • B Brady Kelly

        Why are you adding the custom property? If it is to use in the DisplayColumn metadata attribute, you can override ToString on your entity to return the full name, and remove the DisplayColumn attribute, and the ToString value will be used instead for FK displays.

        B Offline
        B Offline
        brinkerville
        wrote on last edited by
        #3

        I am trying to acheive the same goal. However, when I try and access one of the properties from the entity model that I have configured I get the following error message: Server Error in '/' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS1061: 'Contracts.CONTRACT_PERIOD' does not contain a definition for 'start_date' and no extension method 'start_date' accepting a first argument of type 'Contracts.CONTRACT_PERIOD' could be found (are you missing a using directive or an assembly reference?) Source Error: Line 39: StringBuilder sb = new StringBuilder(); Line 40: sb.Append("("); Line 41: sb.Append(this.start_date.ToShortDateString()); Line 42: sb.Append(" - "); Line 43: sb.Append(this.end_date.ToShortDateString()); Source File: c:\Documents and Settings\...\My Documents\Visual Studio 2010\Projects\...\Contracts\App_Code\Metadata.cs Line: 41

        1 Reply Last reply
        0
        • K Kris Penner

          Hello, I am trying to display in a Dynamic Data app, a custom property added to the partial class of an ADO.NET Entity Framework entity class. For example, where Person is a entity in a ADO.NET Entity Framework model, I would add:

          public partial class Person
          {
          public string FullName { get { return FirstName + " " + LastName; } }
          }

          However, with Dynamic Data, it uses the internal System.Web.DynamicData.ModelProviders.EFTableProvider for generating its columns collection which only allows properties defined in the entity model to be displayed - as in only the database columns, not custom added ones. Does anyone know any work arounds to this, or is it possible and I am missing something obvious. Seems silly I can't do this. LINQ to SQL with Dynamic Data can do this easy as it uses reflection in its DLinqTableProvider to find all properties in the object, not just those with mappings to database fields. EFTableProvider's enumerator to create its columns for Dynamic Data: foreach (EdmMember member in entityType.get_Members()) // only entity DB mapped fields are returned in the Members property DLinqTableProvider's enumerator to create its columns for Dynamic Data: IEnumerator<PropertyInfo> enumerator = this.GetOrderedProperties(rowType.get_Type()).GetEnumerator() where GetOrderedProperties returns a list of properties based on reflection: PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); Anyone have any thoughts on how to do this effectively? I need the many-to-many relationship management that Entity Framework provides - otherwise I would stick with LINQ to SQL. Thanks for any help! Cheers, kris

          M Offline
          M Offline
          Martintuk
          wrote on last edited by
          #4

          Hey! Same problem here... Can't believe adding calculated properties can be so hard or even not supported... Found any solution to this? Martin

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups