public static object InsertInto(this object o, string table, ConnectionProfile connectionProfile = null) { if (connectionProfile == null) connectionProfile = new ConnectionProfile(); DynamicRepository dynamicModel = new DynamicRepository(connectionProfile, table, "Id"); return dynamicModel.Insert(o); }
public DynamicModels Execute(dynamic options, DynamicRepository repository, string associationName, string selectClause, IEnumerable<dynamic> models, string parentMemberName) { if (ShouldDiscardCache(options)) Cache = null; if (Cache != null) return Cache; var many = repository.Query(selectClause).ToList(); foreach (var item in many) { var model = models.First(s => s.Id == item.GetMember(parentMemberName)); item.SetMember(model.GetType().Name, model); } foreach (var model in models) { var assocation = model.AssociationNamed(associationName); var relatedTo = many.Where(s => s.GetMember(model.GetType().Name).Equals(model)).Select(s => s); assocation.EagerLoadMany.Cache = new DynamicModels(relatedTo); assocation.AddNewAssociationMethod(assocation.EagerLoadMany.Cache, model); } return new DynamicModels(many); }
void saving_dynamic_params() { before = () => { seed = new Seed(); seed.PurgeDb(); seed.CreateTable("Blogs", new dynamic[] { new { Id = "int", Identity = true, PrimaryKey = true }, new { Title = "nvarchar(255)" } }).ExecuteNonQuery(); nameValueCollection.Add("Title", "Some Title"); }; it["persists saveable values to the database"] = () => { var blogs = new DynamicRepository("Blogs"); var blogId = blogs.Insert(asDynamic); var blog = blogs.Single(blogId); (blog.Title as string).should_be("Some Title"); }; }
public virtual void AddRepository(DynamicModels collection, DynamicRepository repository) { collection.SetMember("Repository", repository); }
public BelongsTo(DynamicRepository repository) : this(repository, null) { }
public HasOneThrough(DynamicRepository repository, DynamicRepository through) : this(repository, through, null) { }
public HasOne(DynamicRepository repository) : this(repository, null) { }
public HasMany(DynamicRepository repository, string methodName) { this.Repository = repository; this.MethodName = methodName ?? repository.TableName; }
public HasMany(DynamicRepository repository, string named) { this.repository = repository; this.named = named ?? repository.GetType().Name; }
public BelongsTo(DynamicRepository repository, string named) { this.Repository = repository; Named = named ?? Singular(repository); }
public HasOneThrough(DynamicRepository repository, DynamicRepository through, string named) { this.Repository = repository; this.through = through; Named = named ?? Singular(Repository); }
public HasOne(DynamicRepository repository, string named) { this.Repository = repository; Named = named ?? Singular(Repository); }
public static DynamicRepository RepositoryFor(string tableName) { var repo = new DynamicRepository(tableName); AssociationByConventions.ApplyProjection(repo); return repo; }
public HasManyThrough(DynamicRepository repository, DynamicRepository through, string methodName) { this.Repository = repository; this.through = through; this.throughTable = through.TableName; this.MethodName = methodName ?? repository.TableName; }
public HasManyThrough(DynamicRepository repository, DynamicRepository through, string named) { this.repository = repository; this.through = through; this.named = named ?? repository.GetType().Name; }
public HasMany(DynamicRepository repository) : this(repository, null) { }
public HasOne(DynamicRepository repository) { this.repository = repository; }
public HasManyAndBelongsTo(DynamicRepository repository, DynamicRepository reference) { Repository = repository; this.reference = reference; var sorted = new[] { repository.TableName, reference.TableName }.OrderBy(s => s); throughTable = sorted.First() + sorted.Last(); MethodName = repository.TableName; }
public HasOneThrough(DynamicRepository repository, DynamicRepository through) { this.repository = repository; this.through = through; }
public HasOne(DynamicRepository repository, string methodName) { this.Repository = repository; MethodName = methodName ?? Singular(Repository); }
public BelongsTo(DynamicRepository repository) { this.repository = repository; name = Singular(repository); }
public HasOneThrough(DynamicRepository repository, DynamicRepository through, string methodName) { this.Repository = repository; this.through = through; MethodName = methodName ?? Singular(Repository); }
public Uniqueness(string property, DynamicRepository usingRepository) : base(property) { Repository = usingRepository; }
public BelongsTo(DynamicRepository repository, string methodName) { this.Repository = repository; MethodName = methodName ?? Singular(repository); }
public static DynamicModels Execute(IEnumerable<dynamic> models, DynamicRepository repository, string associationName, string sql, Func<dynamic, dynamic, bool> findClause) { var belongsResult = new List<dynamic>(repository.Query(sql)); foreach (var item in belongsResult) { var relatedModels = models.Where(s => findClause(item, s)); foreach (var relateModel in relatedModels) { var association = relateModel.AssociationNamed(associationName); association.Model = item; var propName = relateModel.GetType().Name; if (item.RespondsTo(propName)) { ConvertToList(propName, item); item.GetMember(propName).Add(relateModel); } else { item.SetMember(propName, relateModel); } } } return new DynamicModels(belongsResult); }
public static DynamicRepository RepositoryFor(string tableName, string connectionString) { var repo = new DynamicRepository(new ConnectionProfile { ConnectionString = connectionString }, tableName); AssociationByConventions.ApplyProjection(repo, connectionString); return repo; }
void mass_assignment() { before = () => { seed = new Seed(); seed.PurgeDb(); seed.CreateTable("Users", new dynamic[] { new { Id = "int", Identity = true, PrimaryKey = true }, new { Name = "nvarchar(255)" }, new { IsAdmin = "bit", Default = false } }).ExecuteNonQuery(); nameValueCollection.Add("Name", "John"); nameValueCollection.Add("IsAdmin", "true"); }; it["allows the ability to exclude fields"] = () => { var users = new DynamicRepository("Users"); var userId = users.Insert(asDynamic.Exclude("IsAdmin")); var user = users.Single(userId); (user.Name as string).should_be("John"); ((bool)user.IsAdmin).should_be(false); }; it["allows the ability to select fields"] = () => { var users = new DynamicRepository("Users"); var userId = users.Insert(asDynamic.Select("Name")); var user = users.Single(userId); (user.Name as string).should_be("John"); ((bool)user.IsAdmin).should_be(false); }; }