public virtual void From() { if (RunningUnderScenarioModel) { _query = Query.From(Exp.Variable(ResContainer)); _pType = ResContainer.BaseType.ClientClrType; AstoriaTestLog.WriteLineIgnore("Query.From(" + ResContainer.Name + ")"); } else { ScanModel model = new ScanModel(_workspace); ModelEngine engine = new ModelEngine(this.Engine, model); engine.Run(); this.ResContainer = model.ResultContainer; _query = Query.From(Exp.Variable(model.ResultContainer)); _pType = model.ResultContainer.BaseType.ClientClrType; AstoriaTestLog.WriteLineIgnore("Query.From(" + model.ResultContainer.Name + ")"); } _action = LastAction.From; IsCount = false; }
protected object GetResource(bool existing, out string entitySetName, out ResourceContainer resContainer) { ScanModel model = new ScanModel(_workspace); ModelEngine engine = new ModelEngine(); engine.Models.Add(model); engine.Run(); entitySetName = ""; resContainer = null; if (!model.CanInsert) return null; object newResource = Activator.CreateInstance(model.Result.ClientClrType); string propName = null; object propValue = null; entitySetName = model.ResultContainer.Name; resContainer = model.ResultContainer; foreach (ResourceProperty property in model.Result.Properties.Where(p => p.PrimaryKey != null || p.Facets.Nullable == false)) { if (!property.IsComplexType && !property.IsNavigation) //&& !property.Facets.ServerGenerated) { propValue = Resource.CreateValue(property).ClrValue; propName = property.Name; newResource.GetType().GetProperty(propName).SetValue(newResource, propValue, new object[] { }); } } if (existing) { KeyExpression key = _workspace.GetRandomExistingKey(model.ResultContainer, model.Result); if (key != null) newResource.GetType().GetProperty(key.Properties[0].Name).SetValue(newResource, key.Values[0].ClrValue, new object[] { }); else return null; } return newResource; }
public virtual void AttachObject() { //if (RunningUnderLinkModel) // { // object detachMe = RandomTrackedResource; // Context.Detach( RandomTrackedResource ); // Context.AttachTo( CurrentResourceSet, detachMe ); // } //else { ScanModel model = new ScanModel(_workspace); ModelEngine engine = new ModelEngine(); engine.Models.Add(model); engine.Run(); if (!model.CanInsert) return; object newResource = Activator.CreateInstance(model.Result.ClientClrType); KeyExpression key = Workspace.GetRandomExistingKey(model.ResultContainer, model.Result); if (key != null) newResource.GetType().GetProperty(key.Properties[0].Name).SetValue(newResource, key.Values[0].ClrValue, new object[] { }); else return; try { Context.AttachTo(model.ResultContainer.Name, newResource); } catch (InvalidOperationException e) { return; } AstoriaTestLog.WriteLine("Attaching entity " + model.ResultContainer.BaseType.Name); _action = LastAction.AttachObject; _state = EntityState.Unchanged; this.CurrentResource = newResource; this.CanInsert = model.CanInsert; this.CanDelete = model.CanDelete; this.ResContainer = model.ResultContainer; this.ResType = model.Result; } }
public virtual void From() { if (RunningUnderScenarioModel) { _query = Query.From( Exp.Variable( ResContainer ) ); _pType = ResContainer.BaseType.ClientClrType; AstoriaTestLog.WriteLineIgnore( "Query.From(" + ResContainer.Name + ")" ); } else { ScanModel model = new ScanModel( _workspace ); ModelEngine engine = new ModelEngine( this.Engine, model ); engine.Run(); this.ResContainer = model.ResultContainer; _query = Query.From( Exp.Variable( model.ResultContainer ) ); _pType = model.ResultContainer.BaseType.ClientClrType; AstoriaTestLog.WriteLineIgnore( "Query.From(" + model.ResultContainer.Name + ")" ); } _action = LastAction.From; IsCount = false; }