Welcome

首页 / 软件开发 / .NET编程技术 / nhibernate执行sql类

nhibernate执行sql类2011-04-05 博客园 loswing用户要求,可以自己输入其自己乱定义的sql。。无法,随便弄了个

估计有问题。不过也无法。先用这把

本来把想存储field类别,可木找到这么获取,先留着吧,以后该下。

1 public class MySQLField
2 {
3 private string _name = String.Empty;
4 private string _value = String.Empty;
5 private Type _type = null;
6
7 public string Name
8 {
9 get { return _name; }
10 set { _name = value; }
11 }
12
13 public string Value
14 {
15 get { return _value; }
16 set { _value = value; }
17 }
18
19 public Type FieldType
20 {
21 get { return _type; }
22 set { _type = value; }
23 }
24
25
26 public override string ToString()
27 {
28 return Value;
29 }
30
31 public override int GetHashCode()
32 {
33 return Name.GetHashCode();
34 }
35 }

重写了下[]和add 不过因为偷懒木继承IList ,不知道会出问题不

1 public class MySQLRow : System.Collections.Generic.List<MySQLField>
2 {
3 public new MySQLField this[string index]
4 {
5 set
6 {
7 base.Add(value);
8 }
9 get
10 {
11 return this.GetField(index);
12 }
13 }
14
15 private System.Collections.Hashtable _strField = new Hashtable();
16
17
18 public string GetFieldValues (string key)
19 {
20 if (_strField.ContainsKey(key))
21 return (string)_strField[key];
22 else
23 return string.Empty;
24 }
25
26 public MySQLField GetField(string key)
27 {
28 if(_strField.ContainsKey(key))
29 return new MySQLField()
30 {
31 Name = key,
32 Value = GetFieldValues(key)
33 };
34 return null;
35 }
36
37
38
39 public new void Add(MySQLField item)
40 {
41 string key = item.Name;
42 if (_strField.ContainsKey(key))
43 _strField.Remove(key);
44 _strField.Add(key, item.Value);
45
46 if (Contains(item))
47 _strField.Remove (item);
48
49 base.Add(item);
50 }
51
52
53 }