TitanChase

Table.cs

May 10th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace SqlDb
  9. {
  10. public class Table
  11. {
  12. public string Name { get; private set; }
  13. public string Schema { get; private set; }
  14.  
  15. public Table(string Name, string Schema = "dbo")
  16. {
  17. this.Name = Name;
  18. this.Schema = Schema;
  19. }
  20.  
  21. public override string ToString()
  22. {
  23. return string.Format("[{0}].[{1}]", this.Schema, this.Name);
  24. }
  25.  
  26. public bool Exists()
  27. {
  28. return new Table("TABLES", "INFORMATION_SCHEMA").Select("*", "TABLE_NAME = @Table AND TABLE_SCHEMA = @Schema", "Table", this.Name, "Schema", this.Schema).Rows.Count == 1;
  29. }
  30.  
  31. public DataTable Select(string What = "*", string Where = "", params object[] list)
  32. {
  33. return Sql.Instance.Query(string.Format("select {0} from {1} {2}", What, ToString(), !string.IsNullOrEmpty(Where) ? "where " + Where : ""), list);
  34. }
  35. }
  36. }
Add Comment
Please, Sign In to add comment