2 using System.Collections.Generic;
10 namespace Deveel.Data.Mapping {
16 typeMappings =
new Dictionary<Type, TypeMapping>();
17 relationships =
new List<Relationship>();
21 typeMappings[mapping.
Type] = mapping;
25 if (relationship == null)
26 throw new ArgumentNullException(
"relationship");
29 throw new ArgumentException(String.Format(
"Type '{0}' source of the relationship is not mapped.", relationship.
SourceType));
31 throw new ArgumentException(String.Format(
"Type '{0}' destination of the relationship is not mapped.", relationship.
TargetType));
33 var typeMapping = GetMapping(relationship.
SourceType);
34 if (!typeMapping.IsMemberMapped(relationship.
SourceMember))
35 throw new ArgumentException(String.Format(
"Member '{0}' in type '{1}' source of the relationship is not mapped",
38 relationships.Add(relationship);
41 public IEnumerable<Type> Types {
42 get {
return typeMappings.Keys.AsEnumerable(); }
45 public IEnumerable<TypeMapping> TypeMappings {
46 get {
return typeMappings.Values.AsEnumerable(); }
49 public IEnumerable<Relationship> Relationships {
50 get {
return relationships.AsReadOnly(); }
54 return typeMappings.ContainsKey(type);
59 throw new ArgumentNullException(
"type");
62 if (!typeMappings.TryGetValue(type, out mapping))
69 return relationships.FirstOrDefault(x => x.SourceType == sourceType &&
70 x.SourceMember == sourceMember);
QueryMapping CreateQueryMapping()
readonly Dictionary< Type, TypeMapping > typeMappings
void Map(TypeMapping mapping)
void AddRelationship(Relationship relationship)
readonly List< Relationship > relationships
TypeMapping GetMapping(Type type)
Relationship GetRelationship(Type sourceType, string sourceMember)