This is a migrated thread and some comments may be shown as answers.

Mapping a KeyedCollection derived class

2 Answers 62 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Paulhenri
Top achievements
Rank 1
Paulhenri asked on 13 Sep 2013, 07:43 AM
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 Answers, 1 is accepted

Sort by
0
Paulhenri
Top achievements
Rank 1
answered on 13 Sep 2013, 02:49 PM
And a have one more question: is it possible to map an ObservableCollection with "code-only" mapping?

Thx

Paulhenri
0
Kaloyan Nikolov
Telerik team
answered on 16 Sep 2013, 04:13 PM
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.

Tags
Data Access Free Edition
Asked by
Paulhenri
Top achievements
Rank 1
Answers by
Paulhenri
Top achievements
Rank 1
Kaloyan Nikolov
Telerik team
Share this question
or