/SimpleCrud/Types/LongType.cs

http://github.com/cordjr/simplecrud · C# · 41 lines · 30 code · 11 blank · 0 comment · 8 complexity · 13fd181fb9a3dc39ad54e124b4a1dac5 MD5 · raw file

  1. using System;
  2. using System.Data.Common;
  3. using SimpleCrud.Core;
  4. namespace SimpleCrud.Types {
  5. public class LongType : IDBType {
  6. public void BindToCommand(DbCommand cmd, int index, object value) {
  7. if (value == null) {
  8. cmd.Parameters[index].Value = DBNull.Value;
  9. } else {
  10. cmd.Parameters[index].Value = (long)value;
  11. }
  12. }
  13. public void BindToCommand(DbCommand cmd, string paramName, object value) {
  14. if (value == null) {
  15. cmd.Parameters[paramName].Value = DBNull.Value;
  16. } else {
  17. cmd.Parameters[paramName].Value = (long)value;
  18. }
  19. }
  20. public object GetFromDataReader(DbDataReader rset, int index) {
  21. return rset.GetValue(index) == DBNull.Value ? 0 : rset.GetValue(index);
  22. }
  23. public object GetFromDataReader(DbDataReader rset, string fieldName) {
  24. return rset[fieldName] == DBNull.Value ? 0 : rset[fieldName];
  25. }
  26. public Type GetImplType() {
  27. return typeof (long);
  28. }
  29. }
  30. }