private string CreateDbSetType(EntityDefinition entityDef, DbSetInfo dbSetInfo, DotNet2TS dotNet2TS) { StringBuilder sb = new StringBuilder(512); string dbSetType = GetDbSetTypeName(dbSetInfo.dbSetName); List <Association> childAssoc = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList(); List <Association> parentAssoc = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList(); FieldsList fieldInfos = dbSetInfo.fieldInfos; Field[] pkFields = dbSetInfo.GetPKFields(); string pkVals = ""; foreach (Field pkField in pkFields) { if (!string.IsNullOrEmpty(pkVals)) { pkVals += ", "; } pkVals += pkField.fieldName.ToCamelCase() + ": " + GetFieldDataType(pkField); } Dictionary <string, Func <TemplateParser.Context, string> > dic = new Dictionary <string, Func <TemplateParser.Context, string> > { { "DBSET_NAME", (context) => dbSetInfo.dbSetName }, { "DBSET_TYPE", (context) => dbSetType }, { "ENTITY_NAME", (context) => entityDef.entityName }, { "ASPECT_NAME", (context) => entityDef.aspectName }, { "INTERFACE_NAME", (context) => entityDef.interfaceName }, { "VALS_NAME", (context) => entityDef.valsName }, { "DBSET_INFO", (context) => { //we are making copy of the object, in order that we don't change original object //while it can be accessed by other threads //we change our own copy, making it threadsafe DbSetInfo copy = dbSetInfo.ShallowCopy(); copy.SetFieldInfos(new FieldsList()); //serialze with empty field infos return(_serializer.Serialize(copy)); } }, { "FIELD_INFOS", (context) => _serializer.Serialize(dbSetInfo.fieldInfos) }, { "CHILD_ASSOC", (context) => _serializer.Serialize(childAssoc) }, { "PARENT_ASSOC", (context) => _serializer.Serialize(parentAssoc) }, { "QUERIES", (context) => CreateDbSetQueries(dbSetInfo, dotNet2TS) }, { "CALC_FIELDS", (context) => CreateCalcFields(dbSetInfo) }, { "PK_VALS", (context) => pkVals } }; return(_dbSetTemplate.ToString(dic)); }
private string createDbSetType(string entityDef, DbSetInfo dbSetInfo) { var sb = new StringBuilder(512); var dbSetType = GetDbSetTypeName(dbSetInfo.dbSetName); var entityTypeName = GetEntityTypeName(dbSetInfo.dbSetName); var entityInterfaceName = GetEntityInterfaceName(dbSetInfo.dbSetName); var childAssoc = _associations.Where(assoc => assoc.childDbSetName == dbSetInfo.dbSetName).ToList(); var parentAssoc = _associations.Where(assoc => assoc.parentDbSetName == dbSetInfo.dbSetName).ToList(); var fieldInfos = dbSetInfo.fieldInfos; var pkFields = dbSetInfo.GetPKFields(); var pkVals = ""; foreach (var pkField in pkFields) { if (!string.IsNullOrEmpty(pkVals)) { pkVals += ", "; } pkVals += pkField.fieldName.toCamelCase() + ": " + GetFieldDataType(pkField); } Dictionary <string, Func <string> > dic = new Dictionary <string, Func <string> >(); dic.Add("DBSET_NAME", () => dbSetInfo.dbSetName); dic.Add("DBSET_TYPE", () => dbSetType); dic.Add("ENTITY", () => entityDef); dic.Add("ENTITY_TYPE", () => entityTypeName); dic.Add("ENTITY_INTERFACE", () => entityInterfaceName); dic.Add("DBSET_INFO", () => { //we are making copy of the object, in order that we don't change original object //while it can be accessed by other threads //we change our own copy, making it threadsafe var copy = dbSetInfo.ShallowCopy(); copy._fieldInfos = new FieldsList(); //serialze with empty field infos return(_serializer.Serialize(copy)); }); dic.Add("FIELD_INFOS", () => _serializer.Serialize(dbSetInfo.fieldInfos)); dic.Add("CHILD_ASSOC", () => _serializer.Serialize(childAssoc)); dic.Add("PARENT_ASSOC", () => _serializer.Serialize(parentAssoc)); dic.Add("QUERIES", () => createDbSetQueries(dbSetInfo)); dic.Add("CALC_FIELDS", () => createCalcFields(dbSetInfo)); dic.Add("PK_VALS", () => pkVals); return(_dbSetTemplate.ProcessTemplate(dic)); }