// Internal Methods (2) internal bool HasAttribute(string attributeName) { var lowerAttributeName = attributeName.ToLower(); return (EntityInfos.SelectMany(ei => ei.EntityDatas) .Any(ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName))); }
private EntityInfo GetEntityInfo(Type type) { EntityInfo infos; if (!EntityInfos.TryGetValue(type, out infos)) { List <PropertyInfo> singleReferences = type .GetProperties() .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IDbReference))) .ToList(); List <PropertyInfo> multipleReferences = type .GetProperties() .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IList))) .Where(p => p.PropertyType.GetGenericArguments()[0].GetInterfaces().Contains(typeof(IDbReference))) .ToList(); infos = new EntityInfo(); infos.EntityType = type; List <SingleReferenceProperty> single = new List <SingleReferenceProperty>(); List <MultipleReferenceProperty> multiple = new List <MultipleReferenceProperty>(); foreach (PropertyInfo s in singleReferences) { SingleReferenceProperty reference = new SingleReferenceProperty() { PropertyAccessor = s, ReferenceType = s.PropertyType.GetGenericArguments()[0], ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType) }; single.Add(reference); } foreach (PropertyInfo s in multipleReferences) { MultipleReferenceProperty reference = new MultipleReferenceProperty() { PropertyAccessor = s, ReferenceType = s.PropertyType.GetGenericArguments()[0].GetGenericArguments()[0], ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType.GetGenericArguments()[0]) }; multiple.Add(reference); } infos.SingleReferenceInjectors = single; infos.MultipleReferenceInjectors = multiple; EntityInfos.Add(type, infos); } return(infos); }
string ReadFromFile(string entityName) { TextAsset jsonData = Resources.Load("JSON/entityinfos") as TextAsset; EntityInfos entityinfos = JsonUtility.FromJson <EntityInfos>(jsonData.text); foreach (EntityInfo i in entityinfos.entityInfos) { if (entityName == i.name) { return(i.reactionType); } } return(""); }
/// <summary> /// Get the <see cref="EntityInfo"/> object from the cache. /// </summary> /// If the <paramref name="type"/> has no <see cref="EntityInfo"/> then it will add the and return the <see cref="EntityInfo"/>. /// <param name="type"></param> /// <returns></returns> public static EntityInfo GetEntityInfo(Type type) { EntityInfo entityInfo = null; if (EntityInfos.TryGetValue(type.GetHashCode(), out entityInfo)) { return(entityInfo); } entityInfo = new EntityInfo(type); EntityInfos.Add(type.GetHashCode(), entityInfo); return(entityInfo); }
public static EntityDbMappingInfo GetEntityInfo <TEntity>(this EdoContext context) { var entityType = typeof(TEntity); return(EntityInfos.GetOrAdd(entityType, (prop, dbContext) => { var entity = dbContext.Model.FindEntityType(entityType); return new EntityDbMappingInfo() { Table = entity.GetTableName(), Schema = entity.GetSchema() ?? DefaultSchema, PropertyMapping = entity.GetProperties() .ToDictionary(property => property.Name, property => property.GetColumnName()) }; }, context)); }
public static EntityDbMappingInfo GetEntityInfo <TEntity>(this NakijinContext context) { var entityType = typeof(TEntity); return(EntityInfos.GetOrAdd(entityType, (prop, dbContext) => { var entity = dbContext.Model.FindEntityType(entityType) !; var tableName = entity.GetTableName() !; return new EntityDbMappingInfo { Table = tableName, Schema = entity.GetSchema() ?? DefaultSchema, PropertyMapping = entity.GetProperties() .ToDictionary(property => property.Name, property => property.GetDefaultColumnName(StoreObjectIdentifier.Table(tableName, DefaultSchema))) }; }, context)); }
public void UpsertValue(AryaDbDataContext db, string attributeName, string value) { var existingEds = GetValuesForAttribute(db, attributeName, false); EntityData ed = null; if (existingEds.Count > 0) { if (existingEds.Count == 1 && existingEds[0].Value.Equals(value)) { return; } foreach (var existingEd in existingEds) { ed = existingEd; ed.Active = false; } } if (string.IsNullOrEmpty(value)) { return; } var newEd = new EntityData(db) { Attribute = Attribute.GetAttributeFromName(db, attributeName, true, AttributeTypeEnum.Sku), Value = value }; if (ed != null) { ed.EntityInfo.EntityDatas.Add(newEd); } else { EntityInfos.Add(new EntityInfo(db) { EntityDatas = { newEd } }); } }
public bool HasValue(string attributeName, string value) { var lowerAttributeName = attributeName.ToLower(); var lowerValue = value.ToLower(); var entityDatas = EntityInfos.SelectMany(ei => ei.EntityDatas); if (lowerValue.StartsWith("%") && lowerValue.EndsWith("%")) { lowerValue = lowerValue.Substring(1, lowerValue.Length - 2); return (entityDatas.Any( ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName) && ed.Value.ToLower().Contains(lowerValue))); } if (lowerValue.StartsWith("%")) { lowerValue = lowerValue.Substring(1, lowerValue.Length - 1); return (entityDatas.Any( ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName) && ed.Value.ToLower().Contains(lowerValue))); } if (lowerValue.EndsWith("%")) { lowerValue = lowerValue.Substring(0, lowerValue.Length - 1); return (entityDatas.Any( ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName) && ed.Value.ToLower().StartsWith(lowerValue))); } //equals query return (entityDatas.Any( ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName) && ed.Value.ToLower().Equals(lowerValue))); }
internal bool HasValue(string attributeName, string value) { var lowerAttributeName = attributeName.ToLower(); var lowerValue = value.ToLower(); var containsQuery = false; var equalsQuery = false; var endsWithQuery = false; var startsWithQuery = false; if (lowerValue.StartsWith("%") && lowerValue.EndsWith("%")) { containsQuery = true; lowerValue = lowerValue.Substring(1, lowerValue.Length - 2); } else if (lowerValue.StartsWith("%")) { endsWithQuery = true; lowerValue = lowerValue.Substring(1, lowerValue.Length - 1); } else if (lowerValue.EndsWith("%")) { startsWithQuery = true; lowerValue = lowerValue.Substring(0, lowerValue.Length - 1); } else { equalsQuery = true; } return (EntityInfos.SelectMany(ei => ei.EntityDatas) .Any( ed => ed.Active && ed.Attribute.AttributeName.ToLower().Equals(lowerAttributeName) && ((equalsQuery && ed.Value.ToLower().Equals(lowerValue)) || (containsQuery && ed.Value.ToLower().Contains(lowerValue)) || (startsWithQuery && ed.Value.ToLower().StartsWith(lowerValue)) || (endsWithQuery && ed.Value.ToLower().Contains(lowerValue))))); }
Guid ISpell.GetId() { return(EntityInfos.First().ID); }