Exemplo n.º 1
0
        public static void AppendMMLookupSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject firstPart, Type otherType)
        {
            var r = Get(__MMInfos, firstPart.GetType(), otherType);

            if (r.IsEmpty)
            {
                throw new DMError(Translations.LookupHelper_AppendMMLookupSql_Couldnt_fond_many_to_many_relation_between__1__and__1_, firstPart.GetType().Name, otherType.Name);
            }
            if (firstPart.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, firstPart.GetType(), firstPart.ID);
            }

            context.Write("SELECT [{0}] FROM [{1}] WHERE ([{2}] = {3}) and sysState = 0",
                          r.IDColumnName, r.TableName, r.RefColumnName, context.AddParameter(firstPart.ID));
        }
Exemplo n.º 2
0
        public static void AppendMMLookupSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject firstPart, Type otherType)
        {
            var r = Get(__MMInfos, firstPart.GetType(), otherType);

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt fond many-to-many relation between {1} and {1}", firstPart.GetType().Name, otherType.Name);
            }
            if (firstPart.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", firstPart.GetType(), firstPart.ID);
            }

            context.Write("SELECT [{0}] FROM [{1}] WHERE ([{2}] = {3}) and sysState = 0",
                          r.IDColumnName, r.TableName, r.RefColumnName, context.AddParameter(firstPart.ID));
        }
Exemplo n.º 3
0
        public static void AppendMMLinkSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject o1, IIntKeyedDataObject o2)
        {
            if (o1.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", o1.GetType(), o1.ID);
            }
            if (o2.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", o2.GetType(), o2.ID);
            }

            var r = Get(__MMInfos, o1.GetType(), o2.GetType());

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt fond many-to-many relation between {1} and {1}", o1.GetType().Name, o2.GetType().Name);
            }

            context.Write("INSERT INTO [{0}] ([{1}], [{2}]) VALUES ({3}, {4})",
                          r.TableName, r.RefColumnName, r.IDColumnName, context.AddParameter(o1.ID), context.AddParameter(o2.ID));
        }
Exemplo n.º 4
0
        public static void AppendLookupSql([NotNull] SqlSerializationContext context, [NotNull] IIntKeyedDataObject owner, [NotNull] Type detailType, [CanBeNull] IDBPredicate condition)
        {
            var r = Get(__Infos, owner.GetType(), detailType);

            if (r.IsEmpty)
            {
                throw new DMError("Couldnt found relation between {0} and {1}", owner.GetType(), detailType);
            }
            if (owner.ID <= 0)
            {
                throw new DMError("{0} has invalid ID = {1}", owner.GetType().Name, owner.ID);
            }

            context.Write("SELECT ID FROM [{0}] where ([{1}] = {2}) and sysState = 0", r.TableName, r.RefColumnName, context.AddParameter(owner.ID));
            if (condition != null)
            {
                context.Write(" AND (");
                condition.Write(context);
                context.Write(")");
            }
        }
Exemplo n.º 5
0
        public static void AppendMMUnLinkSql([NotNull] SqlSerializationContext context, IIntKeyedDataObject o1, IIntKeyedDataObject o2)
        {
            var r = Get(__MMInfos, o1.GetType(), o2.GetType());

            if (r.IsEmpty)
            {
                throw new DMError(Translations.LookupHelper_AppendMMLookupSql_Couldnt_fond_many_to_many_relation_between__1__and__1_, o1.GetType().Name, o2.GetType().Name);
            }

            if (o1.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, o1.GetType(), o1.ID);
            }
            if (o2.ID <= 0)
            {
                throw new DMError(Translations.LookupHelper_AppendLookupSql_, o2.GetType(), o2.ID);
            }

            context.Write("DELETE [{0}] WHERE [{1}] = {3} AND [{2}] = {4}",
                          r.TableName, r.RefColumnName, r.IDColumnName, context.AddParameter(o1.ID), context.AddParameter(o2.ID));
        }
Exemplo n.º 6
0
 public void UnLink(IIntKeyedDataObject do1, IIntKeyedDataObject do2)
 {
     using (var scope = DBScope("UnLinking " + do1.GetType().Name + ": " + do1.ID + " and " + do2.GetType().Name + ": " + do2.ID))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMUnLinkSql(sc, do1, do2);
             sc.Finish();
             c.LexExecuteNonQuery();
         }
     }
 }
Exemplo n.º 7
0
 public List <int> LookupMany2ManyIds <TDataObject>([NotNull] IIntKeyedDataObject firstPart, [CanBeNull] IDBPredicate condition)
 {
     using (var scope = DBScope("Looking up many-2-many ids between " + firstPart.GetType().Name + " and " + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMLookupSql(sc, firstPart, typeof(TDataObject));
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }
Exemplo n.º 8
0
 public void Link(IIntKeyedDataObject do1, IIntKeyedDataObject do2)
 {
     using (var scope = DBScope("Linking " + do1.GetType().Name + ": " + do1.ID + Translations.DatabaseModel_LookupMany2ManyIds__and_ + do2.GetType().Name + ": " + do2.ID))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMLinkSql(sc, do1, do2);
             sc.Finish();
             c.LexExecuteNonQuery();
         }
     }
 }
Exemplo n.º 9
0
 public List <int> LookupIds <TDataObject>([NotNull] IIntKeyedDataObject owner, [CanBeNull] IDBPredicate condition)
     where TDataObject : IDataObject
 {
     using (var scope = DBScope("Looking up ids of " + owner.GetType().Name + " for " + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendLookupSql(sc, owner, typeof(TDataObject), condition);
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }
Exemplo n.º 10
0
 public List <int> LookupMany2ManyIds <TDataObject>([NotNull] IIntKeyedDataObject firstPart, [CanBeNull] IDBPredicate condition)
 {
     using (var scope = DBScope(Translations.DatabaseModel_LookupMany2ManyIds_Looking_up_many_2_many_ids_between_ + firstPart.GetType().Name + Translations.DatabaseModel_LookupMany2ManyIds__and_ + typeof(TDataObject).Name))
     {
         using (var c = scope.Connection.CreateCommand())
         {
             var sc = new SqlSerializationContext(c);
             LookupHelper.AppendMMLookupSql(sc, firstPart, typeof(TDataObject));
             sc.Finish();
             return(c.FullReadInts());
         }
     }
 }