コード例 #1
0
ファイル: SqlScriptBuilder.cs プロジェクト: tadeuspiat/legacy
        public static string CreateMtmDelete(PropertyDescription pd, PersistentStorage ps, IList <EntityBase> entities)
        {
            RelationAttribute attr = pd.GetAttribute <RelationAttribute>();

            if (attr == null || attr.RelationType != RelationType.ManyToMany)
            {
                throw new Exception("A many-to-many relationship expected");
            }
            string script = "DELETE FROM " + (string.IsNullOrEmpty(attr.SchemaName) ? "" : attr.SchemaName + ".") +
                            attr.MamyToManyRelationTable + "\r\nWHERE ";

            script += attr.MtmRelationTableParentColumn + " IN (";
            string data = "";

            foreach (EntityBase entity in entities)
            {
                if (string.IsNullOrEmpty(data))
                {
                    data = ValueToString(entity.ID);
                }
                else
                {
                    data += ", " + ValueToString(entity.ID);
                }
            }
            script += data + ")\r\n";
            return(script);
        }
コード例 #2
0
ファイル: SqlScriptBuilder.cs プロジェクト: tadeuspiat/legacy
        public static string CreateMtmInsert(PropertyDescription pd, PersistentStorage ps, IList <EntityBase> entities)
        {
            RelationAttribute attr = pd.GetAttribute <RelationAttribute>();

            if (attr == null || attr.RelationType != RelationType.ManyToMany)
            {
                throw new Exception("A many-to-many relationship expected");
            }
            string script = "INSERT INTO " + (string.IsNullOrEmpty(attr.SchemaName) ? "" : attr.SchemaName + ".") +
                            attr.MamyToManyRelationTable + "(" + attr.MtmRelationTableChildColumn + "," + attr.MtmRelationTableParentColumn + ")\r\n";
            string data = "";

            foreach (EntityBase entity in entities)
            {
                foreach (EntityBase e in pd.GetValue <System.Collections.IList>(entity))
                {
                    if (string.IsNullOrEmpty(data))
                    {
                        data = "SELECT " + ValueToString(e.ID) + ", " + ValueToString(entity.ID) + "\r\n";
                    }
                    else
                    {
                        data += "UNION ALL\r\nSELECT " + ValueToString(e.ID) + ", " + ValueToString(entity.ID) + "\r\n";
                    }
                }
            }
            if (string.IsNullOrEmpty(data))
            {
                return("");
            }
            else
            {
                script += data;
            }
            return(script);
        }