public static TypeKey GetTypeKey(Type type) { var table = new TypeTable(type); var key = table.First(col => col.IsPrimaryKey); return((key != null) ? new TypeKey(key.Name, key.Type) : null); }
internal void ReadXml(XmlReader reader, Type type, TypeTable table) { var relation = Relation.OneToOne; var storage = string.Empty; var sourcekey = string.Empty; var refkey = string.Empty; var viewOnly = false; while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "Relation": relation = (reader.Value == "OneToOne") ? Relation.OneToOne : Relation.OneToMany; break; case "Storage": storage = reader.Value; break; case "SourceKey": sourcekey = reader.Value; break; case "ReferenceKey": refkey = reader.Value; break; case "ViewOnly": viewOnly = bool.Parse(reader.Value); break; } } var memberInfo = GetMemberInfo(type, storage); switch (memberInfo.MemberType) { case MemberTypes.Property: var pInfo = memberInfo as PropertyInfo; if (pInfo == null) { break; } ObjectType = pInfo.PropertyType; break; case MemberTypes.Field: var fInfo = memberInfo as FieldInfo; if (fInfo == null) { break; } ObjectType = fInfo.FieldType; break; } Relation = relation; MemberName = storage; SourceKey = sourcekey; ReferenceKey = refkey; ViewOnly = viewOnly; m_memberInfo = memberInfo; var column = table.First(col => col.Name == SourceKey); if (column != null) { SourceKeyColumn = column; } }