예제 #1
0
파일: Query.cs 프로젝트: kujotx/Oak
        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);
        }
예제 #2
0
파일: Association.cs 프로젝트: eugman/Oak
        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");
            };
        }
예제 #4
0
파일: Association.cs 프로젝트: eugman/Oak
 public virtual void AddRepository(DynamicModels collection, DynamicRepository repository)
 {
     collection.SetMember("Repository", repository);
 }
예제 #5
0
파일: Association.cs 프로젝트: eugman/Oak
        public BelongsTo(DynamicRepository repository)
            : this(repository, null)
        {

        }
예제 #6
0
파일: Association.cs 프로젝트: eugman/Oak
 public HasOneThrough(DynamicRepository repository, DynamicRepository through)
     : this(repository, through, null)
 {
 }
예제 #7
0
파일: Association.cs 프로젝트: eugman/Oak
        public HasOne(DynamicRepository repository)
            : this(repository, null)
        {

        }
예제 #8
0
파일: Association.cs 프로젝트: eugman/Oak
        public HasMany(DynamicRepository repository, string methodName)
        {
            this.Repository = repository;

            this.MethodName = methodName ?? repository.TableName;
        }
예제 #9
0
        public HasMany(DynamicRepository repository, string named)
        {
            this.repository = repository;

            this.named = named ?? repository.GetType().Name;
        }
예제 #10
0
 public BelongsTo(DynamicRepository repository, string named)
 {
     this.Repository = repository;
     Named = named ?? Singular(repository);
 }
예제 #11
0
 public HasOneThrough(DynamicRepository repository, DynamicRepository through, string named)
 {
     this.Repository = repository;
     this.through = through;
     Named = named ?? Singular(Repository);
 }
예제 #12
0
        public HasOne(DynamicRepository repository, string named)
        {
            this.Repository = repository;

            Named = named ?? Singular(Repository);
        }
예제 #13
0
        public static DynamicRepository RepositoryFor(string tableName)
        {
            var repo = new DynamicRepository(tableName);

            AssociationByConventions.ApplyProjection(repo);

            return repo;
        }
예제 #14
0
파일: Association.cs 프로젝트: eugman/Oak
        public HasManyThrough(DynamicRepository repository, DynamicRepository through, string methodName)
        {
            this.Repository = repository;

            this.through = through;

            this.throughTable = through.TableName;

            this.MethodName = methodName ?? repository.TableName;
        }
예제 #15
0
        public HasManyThrough(DynamicRepository repository, DynamicRepository through, string named)
        {
            this.repository = repository;

            this.through = through;

            this.named = named ?? repository.GetType().Name;
        }
예제 #16
0
파일: Association.cs 프로젝트: eugman/Oak
        public HasMany(DynamicRepository repository)
            : this(repository, null)
        {

        }
예제 #17
0
 public HasOne(DynamicRepository repository)
 {
     this.repository = repository;
 }
예제 #18
0
파일: Association.cs 프로젝트: eugman/Oak
        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;
        }
예제 #19
0
 public HasOneThrough(DynamicRepository repository, DynamicRepository through)
 {
     this.repository = repository;
     this.through = through;
 }
예제 #20
0
파일: Association.cs 프로젝트: eugman/Oak
        public HasOne(DynamicRepository repository, string methodName)
        {
            this.Repository = repository;

            MethodName = methodName ?? Singular(Repository);
        }
예제 #21
0
 public BelongsTo(DynamicRepository repository)
 {
     this.repository = repository;
     name = Singular(repository);
 }
예제 #22
0
파일: Association.cs 프로젝트: eugman/Oak
 public HasOneThrough(DynamicRepository repository, DynamicRepository through, string methodName)
 {
     this.Repository = repository;
     this.through = through;
     MethodName = methodName ?? Singular(Repository);
 }
예제 #23
0
파일: Validation.cs 프로젝트: girish66/Oak
 public Uniqueness(string property, DynamicRepository usingRepository)
     : base(property)
 {
     Repository = usingRepository;
 }
예제 #24
0
파일: Association.cs 프로젝트: eugman/Oak
        public BelongsTo(DynamicRepository repository, string methodName)
        {
            this.Repository = repository;

            MethodName = methodName ?? Singular(repository);
        }
예제 #25
0
파일: Association.cs 프로젝트: eugman/Oak
        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);
        }
예제 #26
0
파일: Association.cs 프로젝트: eugman/Oak
        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);
            };
        }