Dynamic Data MetaModel doesn't allow to have more Attributes of the same type

Posts   
 
    
Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 02-Jul-2010 10:51:56   

I have class:

[AllowMultiple = true] CustomAttribute : Attribute

When I try add more than one CustomAttribute to MetaColumn, after registering modelprovider, MetaColumn has only the last one of CustomAttributes.

It seams that somewhere the modelprovider did distinct select on the attributes types.

I global.asax in Application_Start a have following code:


    MetaModel model = new MetaModel();

    ContextConfiguration config = new ContextConfiguration();

    config.MetadataProviderFactory =
       (
          type => new Microsoft.Web.DynamicData.InMemoryMetadataTypeDescriptionProvider
              (
                  type, new System.ComponentModel.DataAnnotations.AssociatedMetadataTypeTypeDescriptionProvider(type)
              )
      );


    //** NOW I ADD SOME CustomAttributes TO CustomerEntity's CustomeName FIELD
    My.BLL.AttributesManager.SetAttributesFromDb();

    SD.LLBLGen.Pro.DynamicDataSupportClasses.LLBLGenProDataModelProvider modelProvider =
             new SD.LLBLGen.Pro.DynamicDataSupportClasses.LLBLGenProDataModelProvider(
                   typeof(My.LLBL.EntityType),                          
                   new My.LLBL.Linq.LinqMetaData(),                     
                   new My.LLBL.FactoryClasses.ElementCreator());


    model.RegisterContext(modelProvider, config);

    //and now there is only single custom attribute in
    //model.GetTable("Customer").GetColumn("CustomerName").Attributes

slice from My.BLL.AttributesManager.SetAttributesFromDb


     foreach (IEntityField field in entity.Fields)
     {
          PropertyInfo info = entity.GetType().GetProperty(field.Name);
          List<Attribute> attributes = SecurityManager.GetFieldAttributes(entityType.ToString(), field.Name);

          //attributes contains Attributes like DisplayNameAttribute, ScaffoldAttribute and few CustomAttributes 
          InMemoryMetadataManager.AddColumnAttributes(info, attributes.ToArray());
     } 

Its a very serious problem for me, because a whole DynamicData application is based on Metadata Attributes and there are many customization based on CustomAttributes

Daniel, using v2.6

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jul-2010 21:41:37   

Hi Daniel,

I'm trying to reproduce your problem. I will back to you a.s.a.p.

David Elizondo | LLBLGen Support Team
Liero
User
Posts: 40
Joined: 18-Sep-2009
# Posted on: 06-Jul-2010 10:20:33   

It's ComponentModel feature described here: http://msdn.microsoft.com/en-us/library/6w3a7b50.aspx

For attributes with AttributeUsageAttribute.AllowMultiple set to true, the attribute collection removes duplicate instances. These are instances in which the Attribute.TypeId property returns equal values.

When you define a custom attribute with AttributeUsageAttribute.AllowMultiple set to true, you must override the Attribute.TypeId property to make it unique. If all instances of your attribute are unique, override Attribute.TypeId to return the object identity of your attribute. If only some instances of your attribute are unique, return a value from Attribute.TypeId that would return equality in those cases. For example, some attributes have a constructor parameter that acts as a unique key. For these attributes, return the value of the constructor parameter from the Attribute.TypeId property.

Note: The default implementation of Attribute.TypeId returns the type identity regardless of the value of the AttributeUsageAttribute.AllowMultiple property. In order to return multiple instances of an AttributeUsageAttribute.AllowMultiple attribute from the AttributeCollection, your attribute must override the Attribute.TypeId property.

I will try correct my code

[edit] I tried it and it works. ComponentModel only allows to have an attributes with unique TypeId.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 06-Jul-2010 20:31:44   

So can we consider this thread closed ?

thanks

Matt