DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
TypeMapping.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 
5 namespace Deveel.Data.Mapping {
6  public class TypeMapping {
7  private readonly Dictionary<string, MemberMapping> memberMappings;
8 
9  internal TypeMapping(MappingModel model, Type type, string tableName) {
10  Model = model;
11  Type = type;
12  TableName = tableName;
13  memberMappings = new Dictionary<string, MemberMapping>();
14  }
15 
16  public MappingModel Model { get; private set; }
17 
18  public Type Type { get; private set; }
19 
20  public string TableName { get; private set; }
21 
22  public IEnumerable<MemberMapping> Members {
23  get { return memberMappings.Values.AsEnumerable(); }
24  }
25 
26  public IEnumerable<string> MemberNames {
27  get { return memberMappings.Keys.AsEnumerable(); }
28  }
29 
30  internal void AddMember(MemberMapping mapping) {
31  memberMappings[mapping.MemberName] = mapping;
32  }
33 
34  public MemberMapping GetMember(string memberName) {
35  if (String.IsNullOrEmpty(memberName))
36  throw new ArgumentNullException("memberName");
37 
38  MemberMapping mapping;
39  if (!memberMappings.TryGetValue(memberName, out mapping))
40  return null;
41 
42  return mapping;
43  }
44 
45  public bool IsMemberMapped(string memberName) {
46  if (String.IsNullOrEmpty(memberName))
47  throw new ArgumentNullException("memberName");
48 
49  return memberMappings.ContainsKey(memberName);
50  }
51 
52  public bool IsColumn(string memberName) {
53  // TODO: handle also relationships in the TypeMapping
54  return IsMemberMapped(memberName);
55  }
56 
57  public bool IsPrimaryKey(string memberName) {
58  var member = GetMember(memberName);
59  if (member == null)
60  return false;
61 
62  return member.PrimaryKey;
63  }
64 
65  public bool IsUniqueKey(string memberName) {
66  var member = GetMember(memberName);
67  if (member == null)
68  return false;
69 
70  return member.UniqueKey;
71  }
72  }
73 }
readonly Dictionary< string, MemberMapping > memberMappings
Definition: TypeMapping.cs:7
bool IsUniqueKey(string memberName)
Definition: TypeMapping.cs:65
bool IsMemberMapped(string memberName)
Definition: TypeMapping.cs:45
bool IsColumn(string memberName)
Definition: TypeMapping.cs:52
void AddMember(MemberMapping mapping)
Definition: TypeMapping.cs:30
bool IsPrimaryKey(string memberName)
Definition: TypeMapping.cs:57
MemberMapping GetMember(string memberName)
Definition: TypeMapping.cs:34
TypeMapping(MappingModel model, Type type, string tableName)
Definition: TypeMapping.cs:9