public static void Initialize(this DbSetInfo dbSetInfo, Type serviceType) { var fbo = dbSetInfo.GetFieldByOrdinal(); var fbn = dbSetInfo.GetFieldByNames(); dbSetInfo.InitMethods(serviceType); }
public object GetTypedValue(Type entityType, DbSetInfo dbSetInfo) { FieldInfo fi = dbSetInfo.GetFieldByNames()[this.fieldName]; PropertyInfo pinfo = entityType.GetProperty(fi.fieldName); if (pinfo == null) throw new Exception(string.Format(ErrorStrings.ERR_PROPERTY_IS_MISSING, entityType.Name, fi.fieldName)); Type propType = pinfo.PropertyType; return DataHelper.ConvertToTyped(propType, fi.dataType, fi.dateConversion, this.val); }
public static void Initialize(this DbSetInfo dbSetInfo, IServiceContainer services) { dbSetInfo._fieldsByNames = new Dictionary <string, Field>(); var i = 0; var fieldInfos = dbSetInfo.fieldInfos.ToArray(); var cnt = fieldInfos.Length; for (i = 0; i < cnt; ++i) { services.DataHelper.ForEachFieldInfo("", fieldInfos[i], (fullName, fieldInfo) => { fieldInfo._FullName = fullName; dbSetInfo._fieldsByNames.Add(fullName, fieldInfo); }); } SetOrdinal(fieldInfos); var pkFields = dbSetInfo.GetPKFields(); if (pkFields.Length < 1) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_DBSET_HAS_NO_PK, dbSetInfo.dbSetName)); } var fbn = dbSetInfo.GetFieldByNames(); }
public Field getFieldInfo(DbSetInfo dbSetInfo, string fullName) { var fieldsByName = dbSetInfo.GetFieldByNames(); return(fieldsByName[fullName]); }
private void ProcessAssociation(Association assoc, DbSetsDictionary dbSets, AssociationsDictionary associations) { if (string.IsNullOrWhiteSpace(assoc.name)) { throw new DomainServiceException(ErrorStrings.ERR_ASSOC_EMPTY_NAME); } if (!dbSets.ContainsKey(assoc.parentDbSetName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_PARENT, assoc.name, assoc.parentDbSetName)); } if (!dbSets.ContainsKey(assoc.childDbSetName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_CHILD, assoc.name, assoc.childDbSetName)); } DbSetInfo childDb = dbSets[assoc.childDbSetName]; DbSetInfo parentDb = dbSets[assoc.parentDbSetName]; Dictionary <string, Field> parentDbFields = parentDb.GetFieldByNames(); Dictionary <string, Field> childDbFields = childDb.GetFieldByNames(); //check navigation field //dont allow to define it explicitly, the association adds the field by itself (implicitly) if (!string.IsNullOrEmpty(assoc.childToParentName) && childDbFields.ContainsKey(assoc.childToParentName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.childToParentName)); } //check navigation field //dont allow to define it explicitly, the association adds the field by itself (implicitly) if (!string.IsNullOrEmpty(assoc.parentToChildrenName) && parentDbFields.ContainsKey(assoc.parentToChildrenName)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.parentToChildrenName)); } if (!string.IsNullOrEmpty(assoc.parentToChildrenName) && !string.IsNullOrEmpty(assoc.childToParentName) && assoc.childToParentName == assoc.parentToChildrenName) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_NAV_FIELD, assoc.name, assoc.parentToChildrenName)); } foreach (FieldRel frel in assoc.fieldRels) { if (!parentDbFields.ContainsKey(frel.parentField)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_PARENT_FIELD, assoc.name, frel.parentField)); } if (!childDbFields.ContainsKey(frel.childField)) { throw new DomainServiceException(string.Format(ErrorStrings.ERR_ASSOC_INVALID_CHILD_FIELD, assoc.name, frel.childField)); } } //indexed by Name associations.Add(assoc.name, assoc); if (!string.IsNullOrEmpty(assoc.childToParentName)) { StringBuilder sb = new StringBuilder(120); string dependentOn = assoc.fieldRels.Aggregate(sb, (a, b) => a.Append((a.Length == 0 ? "" : ",") + b.childField), a => a).ToString(); //add navigation field to dbSet's field collection Field fld = new Field { fieldName = assoc.childToParentName, fieldType = FieldType.Navigation, dataType = DataType.None, dependentOn = dependentOn }; fld.SetTypeScriptDataType(TypeScriptHelper.GetEntityInterfaceName(parentDb.dbSetName)); childDb.fieldInfos.Add(fld); } if (!string.IsNullOrEmpty(assoc.parentToChildrenName)) { StringBuilder sb = new StringBuilder(120); Field fld = new Field { fieldName = assoc.parentToChildrenName, fieldType = FieldType.Navigation, dataType = DataType.None }; fld.SetTypeScriptDataType($"{TypeScriptHelper.GetEntityInterfaceName(childDb.dbSetName)}[]"); //add navigation field to dbSet's field collection parentDb.fieldInfos.Add(fld); } }
public Field GetFieldInfo(DbSetInfo dbSetInfo, string fullName) { System.Collections.Generic.Dictionary <string, Field> fieldsByName = dbSetInfo.GetFieldByNames(); return(fieldsByName[fullName]); }