Esempio n. 1
0
        /// <summary>
        /// 构造一个实体的数据源节点。
        /// </summary>
        /// <param name="repository">本实体数据源来自于这个实体仓库。</param>
        /// <param name="alias">同一个实体仓库可以表示多个不同的数据源。这时,需要这些不同的数据源指定不同的别名。</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">entityRepository</exception>
        public ITableSource Table(IRepository repository, string alias = null)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("entityRepository");
            }

            var dbTable = (repository as IRepositoryInternal).RdbDataProvider.DbTable;

            if (dbTable == null)
            {
                ORMHelper.ThrowBasePropertyNotMappedException(repository.EntityType);
            }

            //构造一个 EntitySource 对象。
            //在构造 TableSource 时,不必立刻为所有属性生成相应的列。必须使用懒加载。
            var table = new TableSource();

            table._dbTable = dbTable;

            var res = table as ITableSource;

            res.EntityRepository = repository;
            table.TableName      = dbTable.Name;
            table.Alias          = alias;

            return(table);
        }