Mapping a KeyedCollection derived class

Thread is closed for posting
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.HasProperty(referenceTable => referenceTable.Id).IsIdentity();
    referenceTableConfiguration.HasProperty(p => p.IsValid).AsTransient();
    referenceTableConfiguration.HasAssociation(r => r.Ranges).MapJoinTable("RefTableJoin");
    MappingConfiguration<ReferenceTableRange> referenceTableRangeConfiguration = new MappingConfiguration<ReferenceTableRange>();
    referenceTableRangeConfiguration.HasProperty(range => range.ReferenceTableRangeId).IsIdentity();
    Is there a way to achieve this?

  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?


  3. Kaloyan Nikolov
    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.

    Kaloyan Nikolov
    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