Пример #1
0
        public static SqlReference ConvertToObject(DataRow dr)
        {
            SqlReference reference = new SqlReference(dr["PK_Table"].ToString(), dr["FK_Table"].ToString(), dr["Constraint"].ToString(), dr["cKeyCol1"].ToString(), dr["cRefCol1"].ToString(), dr["DeleteCascade"].ToString() == "1", dr["UpdateCascade"].ToString() == "1", TpRelacao.Um_Para_Um, false, false);

            reference.TipoRelacao = TpRelacao.Um_Para_Um;
            return(reference);
        }
Пример #2
0
        public static List <SqlReference> GetReferences(string tableName)
        {
            SqlConnection       connection    = null;
            SqlCommand          selectCommand = null;
            List <SqlReference> list;

            try
            {
                try
                {
                    connection    = new SqlConnection(Program.stringConexao);
                    selectCommand = new SqlCommand(string.Format("exec sp_MStablerefs N'{0}', N'actualtables', N'both', null", tableName), connection);
                    connection.Open();
                    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
                    DataSet        dataSet = new DataSet();
                    adapter.Fill(dataSet);
                    List <SqlReference> list2 = new List <SqlReference>();
                    if ((dataSet != null) && (dataSet.Tables[0].Rows.Count > 0))
                    {
                        foreach (DataRow row in dataSet.Tables[0].Rows)
                        {
                            SqlReference item = SqlReference.ConvertToObject(row);
                            if (item.PkTable.ToLower() == tableName.ToLower())
                            {
                                item.IsCollection = true;
                                item.TipoRelacao  = SqlReference.TpRelacao.Um_Para_Muitos;
                            }
                            list2.Add(item);
                        }
                    }
                    list = list2;
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
                if (connection != null)
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        connection.Close();
                    }
                    connection.Dispose();
                }
                if (selectCommand != null)
                {
                    selectCommand.Dispose();
                }
            }
            return(list);
        }