Beispiel #1
0
        public static void DeleteDataPrimaryKey <T>(this ObjectContext objContext, string IdString) where T : EntityObject
        {
            PropertyInfo entityPrimaryKey = GetEntityPrimaryKey <T>();
            string       queryString      = "it." + entityPrimaryKey.Name + " in  {" + IdString + "}";

            if (entityPrimaryKey.PropertyType == typeof(Guid))
            {
                queryString = "it." + entityPrimaryKey.Name + " in {" + IdString.ConvertGuidID() + "}";
            }
            else if (entityPrimaryKey.PropertyType == typeof(string))
            {
                queryString = "it." + entityPrimaryKey.Name + " in {" + IdString.ConvertStringID() + "}";
            }
            objContext.DeleteData <T>(queryString, new ObjectParameter[0]);
        }
Beispiel #2
0
        /// <summary>
        /// 删除数据
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="objContext">ObjectContext对象</param>
        /// <param name="IdString">主健值字符串</param>
        public static void DeleteDataPrimaryKey <T>(this ObjectContext objContext, string IdString) where T : System.Data.Objects.DataClasses.EntityObject
        {
            PropertyInfo objPropertyInfo = GetEntityPrimaryKey <T>();
            string       condition       = "it." + objPropertyInfo.Name + " in  {" + IdString + "}";

            if (objPropertyInfo.PropertyType == typeof(Guid))
            {
                condition = "it." + objPropertyInfo.Name + " in {" + IdString.FormantEntityGuidID() + "}";
            }
            else if (objPropertyInfo.PropertyType == typeof(string))
            {
                condition = "it." + objPropertyInfo.Name + " in {" + IdString.FormantStringID() + "}";
            }
            objContext.DeleteData <T>(condition);
        }