Esempio n. 1
0
        /// <summary>
        /// 新增实体类型
        /// </summary>
        /// <param name="entityType"></param>
        public static void RegisterType(Type entityType)
        {
            DbMapInfo info     = null;
            string    typename = entityType.FullName;

            if (!MemberDict.TryGetValue(typename, out info))
            {
                var    tableAttr = entityType.GetCustomAttribute <TableAttribute>();
                string tableName = string.IsNullOrEmpty(tableAttr.Name) ? entityType.Name : tableAttr.Name;
                info = new DbMapInfo(tableName, entityType.Name, entityType);
                MemberDict[typename] = info;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 获取实体的主键字段
        /// </summary>
        /// <param name="entityTypeFullName">实体类型全称</param>
        /// <returns>主键字段</returns>
        public static string GetPrimaryKeyField(string entityTypeFullName)
        {
            DbMapInfo info = null;

            if (MemberDict.TryGetValue(entityTypeFullName, out info))
            {
                ColumnMapInfo colinfo = info.ColumnMapInfos.First(e => e.IsPK);
                if (colinfo == null)
                {
                    throw new ArgumentException(string.Format("实体{0}不存在主键字段", entityTypeFullName));
                }
                return(colinfo.PropName);
            }
            else
            {
                throw new ArgumentException(string.Format("实体{0}不存在", entityTypeFullName));
            }
        }