locked
Establishing Order of an Entity Columns (not the Navigation Properties) RRS feed

  • Question

  • User1043796333 posted

    How can you set the order of columns in your MetaData file, not the ones belonging to Navigation Properties?

    They seem to be in the right order in the code behind class of my database model but it seems that they are displayed according to its name not its position

    Problem is that if I try to modify the MetaData file then I got an error:

    Error 1 The type <MyNameSpace><MyDatabaseModelName><myEntityNameMetadata> already contains a definition for
    '<column in conflict>' [path.MetaDataFile.cs] <some numbers> <MyProjectName>

    Thursday, June 23, 2011 11:59 AM

Answers

  • User-330204900 posted

    Your metadata/buddy class should be somthing like this, note the internal class is where you put the metadata. Also I make mine nternal as that hide them when I am working on the model.

    [MetadataTypeAttribute(typeof(Category.CategoryMetadata))]
    public partial class Category
    {
        internal sealed class CategoryMetadata
        {
            public int CategoryID { get; set; }
    
            public string CategoryName { get; set; }
    
            public string Description { get; set; }
    
            public byte[] Picture { get; set; }
    
            public EntityCollection<Product> Products { get; set; }
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 24, 2011 6:16 AM

All replies

  • User-330204900 posted
    [Display(Order=1)]
    Public Object Test { get; set; }
    Thursday, June 23, 2011 12:50 PM
  • User1043796333 posted

    Ok maybe I didn't explain myself clearly:

    You have two MetaData files:

    • The <yourmodel.designer.cs>
      //------------------------------------------------------------------------------
      // <auto-generated>
      // This code was generated from a template.
      //
      // Manual changes to this file may cause unexpected behavior in your application.
      // Manual changes to this file will be overwritten if the code is regenerated.
      // </auto-generated>
      //------------------------------------------------------------------------------
    • A second external MetaData File in which you add custom properties such as UIHint, etc. which is not overwritten as the previous one

    My question is trying to show that if you already have a definition of Public Object Test { get; set; } in your Database Model Designer .cs file then if you try to do what you've suggested here then you'll get the mentioned error:

    Error 1 The type <MyNameSpace><MyDatabaseModelName><myEntityNameMetadata> already contains a definition for
    '<column in conflict>' [path.MetaDataFile.cs] <some numbers> <MyProjectName>

    Thursday, June 23, 2011 2:28 PM
  • User-330204900 posted

    You never make changes to the designer file as it is a code gen file.

    Friday, June 24, 2011 6:13 AM
  • User-330204900 posted

    Your metadata/buddy class should be somthing like this, note the internal class is where you put the metadata. Also I make mine nternal as that hide them when I am working on the model.

    [MetadataTypeAttribute(typeof(Category.CategoryMetadata))]
    public partial class Category
    {
        internal sealed class CategoryMetadata
        {
            public int CategoryID { get; set; }
    
            public string CategoryName { get; set; }
    
            public string Description { get; set; }
    
            public byte[] Picture { get; set; }
    
            public EntityCollection<Product> Products { get; set; }
        }
    }
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 24, 2011 6:16 AM