/// <summary> /// Retrieves an existing entity set, or creates a new one if no matching entityset is found. /// </summary> /// <param name="entitySetName">Entity set name.</param> /// <returns>A ModelEntitySet object.</returns> public ModelEntitySet GetOrCreateEntitySet(string entitySetName) { try { ModelEntitySet modelEntitySet = EntitySets.FirstOrDefault(es => es.Name.Equals(entitySetName)); if (modelEntitySet == null) { modelEntitySet = AddEntitySet(entitySetName); } return(modelEntitySet); } catch (Exception ex) { try { if (!ex.Data.Contains("EDMXType")) { ex.Data.Add("EDMXType", this.GetType().Name); } if (!ex.Data.Contains("EDMXObjectName")) { ex.Data.Add("EDMXObjectName", this.ContainerName); } } catch { } throw; } }
private IEnumerable <StateEntry> GetStateEntries(IEnumerable <Entity> entityList) { var all = EntitySets.SelectMany(x => x.GetAllEntities().OfType <Entity>()).ToArray(); var stateEntries = entityList .Select(e => { Entity local; Entity store; if (e.ChangeTracker.State == ObjectState.Added) { // New entities are required to be equal by reference. // Hence, we're not able to retrieve the local instance. local = e; store = null; } else { // Other are compared by is key equal. local = all.FirstOrDefault(x => x.Equals(e)); if (!ReferenceEquals(null, local)) { local.Errors.AddRange(e.Errors); } store = e; } return(new StateEntry(local, store)); }) .ToList(); return(stateEntries); }
/// <summary> /// Creates and adds a new conceptual model entity set. /// </summary> /// <param name="name">Entity set name for the new entity</param> /// <returns>A ModelEntitySet instance corresponding to the new entity set.</returns> public ModelEntitySet AddEntitySet(string name) { try { if (!EntitySets.Where(es => es.Name == name).Any()) { ModelEntitySet es = new ModelEntitySet(ParentFile, this, name); _modelEntitySets.Add(name, es); es.NameChanged += new EventHandler <NameChangeArgs>(es_NameChanged); es.Removed += new EventHandler(es_Removed); return(es); } else { throw new ArgumentException("An entity set with the name " + name + " already exist in the model."); } } catch (Exception ex) { try { if (!ex.Data.Contains("EDMXType")) { ex.Data.Add("EDMXType", this.GetType().Name); } if (!ex.Data.Contains("EDMXObjectName")) { ex.Data.Add("EDMXObjectName", this.ContainerName); } } catch { } throw; } }
/// <summary> /// Retrieves an existing entityset by name, or creates a new one if no matching entity set exist in the storage model. /// </summary> /// <param name="entitySetName">Name of the entity set to get or create.</param> /// <returns>A StoreEntitySet object.</returns> public StoreEntitySet GetOrCreateEntitySet(string entitySetName) { StoreEntitySet storeEntitySet = EntitySets.FirstOrDefault(es => es.Name.Equals(entitySetName, StringComparison.InvariantCultureIgnoreCase)); if (storeEntitySet == null) { storeEntitySet = AddEntitySet(entitySetName); } return(storeEntitySet); }
private EntitySetBase FindEntitySet(EdmType entityType) { while (entityType != null) { var set = EntitySets.FirstOrDefault(es => es.ElementType == entityType); if (set != null) { return(set); } entityType = entityType.BaseType; } return(null); }
/// <summary> /// Adds a new entity set to the storage model. /// </summary> /// <param name="name">Entity set name for the new entityset.</param> /// <returns>A new StoreEntitySet object.</returns> public StoreEntitySet AddEntitySet(string name) { if (!EntitySets.Where(es => es.Name.Equals(name, StringComparison.InvariantCultureIgnoreCase)).Any()) { StoreEntitySet es = new StoreEntitySet(ParentFile, this, name); _storeEntitySets.Add(name, es); es.NameChanged += new EventHandler <NameChangeArgs>(es_NameChanged); es.Removed += new EventHandler(es_Removed); return(es); } else { throw new ArgumentException("An entity set with the name " + name + " already exist in the model."); } }
public void Build() { if (CheckConfigured) { throw new EntityContextConfigurationException("Already Configured"); } foreach (Type entityType in EntityRelations.Types()) { if (!EntitySets.Contains(entityType)) { throw new EntityContextConfigurationException("EntitySet Not Found For EntityRelation"); } } CheckConfigured = true; }
private string GetEntitySetName(IEdmSchemaType ct) { if (ct.TypeKind != EdmTypeKind.Entity) { return(string.Empty); } #if odataV3 var entitySet = EntitySets .Where(m => m != null && m.ElementType.FullName() == ct.FullName()) .DefaultIfEmpty().First(); #else var entitySet = EntitySets .Where(m => m != null && m.EntityType().FullName() == ct.FullName()) .DefaultIfEmpty().First(); #endif return(entitySet != null ? entitySet.Name : string.Empty); }
public override void LoadContent() { entityFactory = new EntityFactory(new NormalBodyFactory(world)); var entitySet = EntitySets.GameStateSet(entityFactory); var User = Chat.ChatRoom.users.Where(x => x.Value.Admin).FirstOrDefault(); var enemyUser = Chat.ChatRoom.users.Where(x => !x.Value.Admin).FirstOrDefault(); ball = entityFactory.CreateDynamicCircle(520, 435, 15f, "Ball", true); player = entityFactory.CreateDynamicPlayer(917, 752, 30, $"{User.Key},{User.Value.Skin}", true); enemyPlayer = entityFactory.CreateDynamicPlayer(112, 752, 30, $"{enemyUser.Key},{enemyUser.Value.Skin}", true); foot = entityFactory.CreateDynamicBox(250, 350, new Vector2(35, 10), "rfoot", true); enemyFoot = entityFactory.CreateDynamicBox(250, 350, new Vector2(60, 10), "foot", true); legJoint = entityFactory.CreateRevoluteJointJoint(player, foot); enemyLegJoint = entityFactory.CreateRevoluteJointJoint(enemyPlayer, enemyFoot, true); playerFootSpeed = legJoint.MotorSpeed; enemyFootSpeed = enemyLegJoint.MotorSpeed; ballPosition = ball.body.Position; playerPosition = player.body.Position; enemyPlayerPosition = enemyPlayer.body.Position; entitySet.Add(ball); entitySet.Add(enemyPlayer); entitySet.Add(player); entitySet.Add(foot); entitySet.Add(enemyFoot); Game.Game.Entities = entitySet; var inputHandler = new InputHandler(); inputHandler.ReciveHandler = handleInput; if (UDPServer is null) { UDPServer = new UDPServer <Frame>(1337); } MyContactListener.playerScore += PlayerScore; MyContactListener.enemyScore += EnemyScore; Game.Game.IsLive = true; isLoaded = true; }
/// <summary> /// Populates the EntitySets collection from the current DomainContext. /// </summary> void GenerateEntitySets(Type ctxType) { EntitySets.Clear(); if (ctxType != null) { var ctx = Context; foreach (var pi in ctxType.GetProperties()) { var type = pi.PropertyType; if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(DbSet <>) && type.GetGenericArguments().Length == 1) { var objSet = new EntitySet(this, pi); EntitySets.Add(objSet); } } } }
/// <summary> /// Removes all members from the conceptual model. /// </summary> public void Clear() { try { foreach (ModelAssociationSet mas in AssociationSets.ToList()) { mas.Remove(); } foreach (ModelComplexType mct in ComplexTypes.ToList()) { mct.Remove(); } foreach (ModelEntityType met in EntityTypes.ToList()) { met.Remove(); } foreach (ModelEntitySet mes in EntitySets.ToList()) { mes.Remove(); } foreach (ModelFunction mf in FunctionImports.ToList()) { mf.Remove(); } } catch (Exception ex) { try { if (!ex.Data.Contains("EDMXType")) { ex.Data.Add("EDMXType", this.GetType().Name); } if (!ex.Data.Contains("EDMXObjectName")) { ex.Data.Add("EDMXObjectName", this.ContainerName); } } catch { } throw; } }
/// <summary> /// Retrieves an existing entityset based on a conceptual model entityset/type, or creates a new one if a match can not be found. /// </summary> /// <param name="modelEntitySet">Conceptual model entity set to match.</param> /// <param name="modelEntityType">Conceptual model entity type to match.</param> /// <param name="schemaName">Database schemaname for the new entity set.</param> /// <param name="tableName">Tablename for the new entityset.</param> /// <returns>A StoreEntitySet object.</returns> public StoreEntitySet GetOrCreateEntitySet(ModelEntitySet modelEntitySet, ModelEntityType modelEntityType, string schemaName, string tableName) { string entitySetName = null; if (!modelEntityType.HasBaseType) { entitySetName = modelEntitySet.Name; } else { entitySetName = modelEntityType.TopLevelBaseType.EntitySet.Name + "_" + modelEntityType.Name; } StoreEntitySet storeEntitySet = EntitySets.FirstOrDefault(es => es.Name.Equals(entitySetName, StringComparison.InvariantCultureIgnoreCase)); if (storeEntitySet == null) { storeEntitySet = AddEntitySet(modelEntitySet, modelEntityType, schemaName, tableName); } return(storeEntitySet); }