Mapping a KeyedCollection derived class

3 posts, 0 answers
  1. Paulhenri
    Paulhenri avatar
    7 posts
    Member since:
    Jan 2013

    Posted 13 Sep 2013 Link to this post

    Hi all!

    I'm using fluent mapping and I'm trying to map a class that derive from KeyedCollection:
    public class RangeCollection : KeyedCollection<Parameter, ReferenceTableRange>
    {
        protected override Parameter GetKeyForItem(ReferenceTableRange item)
        {
            return item.Parameter;
        }
    }
     
    I try to apply the Dictionary property mapping approach, but I get the following exception:

    Not implemented: No SCO factory registered for type: RangeCollection .
    Class: ReferenceTable Field: ranges


    Here is my code:
    MappingConfiguration<ReferenceTable> referenceTableConfiguration = new MappingConfiguration<ReferenceTable>();
    referenceTableConfiguration.MapType().ToTable("ReferenceTable");
    referenceTableConfiguration.HasProperty(referenceTable => referenceTable.Id).IsIdentity();
    referenceTableConfiguration.HasProperty(p => p.IsValid).AsTransient();
    referenceTableConfiguration.HasAssociation(r => r.Ranges).MapJoinTable("RefTableJoin");
    mappingConfigurations.Add(referenceTableConfiguration);
     
    MappingConfiguration<ReferenceTableRange> referenceTableRangeConfiguration = new MappingConfiguration<ReferenceTableRange>();
    referenceTableRangeConfiguration.MapType().ToTable("ReferenceTableRange");
    referenceTableConfiguration.HasProperty(r=>r.Id).IsIdentity();
    referenceTableRangeConfiguration.HasProperty(range => range.ReferenceTableRangeId).IsIdentity();
    mappingConfigurations.Add(referenceTableRangeConfiguration);
     
    Is there a way to achieve this?


    Thanks
  2. Paulhenri
    Paulhenri avatar
    7 posts
    Member since:
    Jan 2013

    Posted 13 Sep 2013 Link to this post

    And a have one more question: is it possible to map an ObservableCollection with "code-only" mapping?

    Thx

    Paulhenri
  3. DevCraft banner
  4. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 16 Sep 2013 Link to this post

    Hi Paulhenri,

    Probably you want a Navigation property witch holds a list of related object pairs. Both element of the pairs a tables in the database. Please correct me if my understanding is wrong. If this is the case then you should use the approach described in this documentation article. For such navigation properties we support collections based on the IDictionary<Tkey, Tvalue> interface only. I would suggest you to use simple Dictionary<Parameter, ReferenceTableRange> instead the KeyedCollection. (see the sample application attached).

    About the second questions for mapping with ObservableCollection:
    Please use the Telerik.OpenAccess.TrackedBindingList collection instead of ObservableCollection. You need just to change the type of the Navigation properties to this one. If you use our wizards and code generation to generate your mapping here is an article describing how to customize the templates in order to change the type of all navigation properties in your model. OpenAccess ORM needs this collection type in order to set the foreign keys automatically when you add a child object in the master's navigation collection property. 

    I hope this helps. Please do not hesitate to contact us again if you have any questions.
     

    Regards,
    Kaloyan Nikolov
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvementsshipped with this release.

Back to Top