{"id":503,"date":"2010-10-01T03:09:56","date_gmt":"2010-10-01T03:09:56","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=503"},"modified":"2010-10-01T03:09:56","modified_gmt":"2010-10-01T03:09:56","slug":"%e6%8d%ae%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e8%a1%a8%e5%ad%97%e6%ae%b5%e4%b8%ba%e5%ae%9e%e4%bd%93%e7%b1%bb%e7%9b%b8%e5%90%8c%e5%90%8d%e7%a7%b0%e5%b1%9e%e6%80%a7%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2010\/10\/01\/%e6%8d%ae%e6%95%b0%e6%8d%ae%e5%ba%93%e7%9a%84%e8%a1%a8%e5%ad%97%e6%ae%b5%e4%b8%ba%e5%ae%9e%e4%bd%93%e7%b1%bb%e7%9b%b8%e5%90%8c%e5%90%8d%e7%a7%b0%e5%b1%9e%e6%80%a7%e8%b5%8b%e5%80%bc\/","title":{"rendered":"\u636e\u6570\u636e\u5e93\u7684\u8868\u5b57\u6bb5\u4e3a\u5b9e\u4f53\u7c7b\u76f8\u540c\u540d\u79f0\u5c5e\u6027\u8d4b\u503c"},"content":{"rendered":"<pre lang=\"csharp\">\r\npublic class DataBaseUntity\r\n    {\r\n        \/\/\u83b7\u53d6\u6570\u636e\u5e93\u6570\u636e\uff1a\u636e\u6570\u636e\u5e93\u7684\u8868\u5b57\u6bb5\u4e3a\u5b9e\u4f53\u7c7b\u76f8\u540c\u540d\u79f0\u5c5e\u6027\u8d4b\u503c\r\n        public static IList<T> SetEntityFromDB<T>(DataTable dt)\r\n        {\r\n            IList<T> list = new List<T>();\r\n            Type type = typeof(T);\r\n            System.Reflection.PropertyInfo[] properties = type.GetProperties();\r\n            foreach (DataRow dr in dt.Rows)\r\n            {\r\n                T t = Activator.CreateInstance<T>();  \r\n                for (int i = 0; i < properties.Length; i++)\r\n                {\r\n                    if (dt.Columns.Contains(properties[i].Name))\r\n                    {\r\n                        properties[i].SetValue(t, dr[properties[i].Name], null);\r\n                    }\r\n                }\r\n                list.Add(t);\r\n            }\r\n\r\n            return list;\r\n        }\r\n\r\n        \/\/\u5411\u6570\u636e\u5e93\u4f20\u53c2\uff1a\u636e\u5b9e\u4f53\u6784\u9020\u53c2\u6570\r\n        public static ArrayList GetParamsFromEntity<T>(T t) {\r\n            Type type = typeof(T);\r\n                      \r\n            System.Reflection.PropertyInfo[] properties = type.GetProperties();\r\n            \/\/SqlParameter[] sps = new SqlParameter[properties.Length-1];\r\n            ArrayList args = new ArrayList();\r\n            SqlParameter sp;\r\n            for (int i = 0; i < properties.Length; i++) {\r\n                args.Add(new SqlParameter(string.Format(\"@{0}\",properties[i].Name),properties[i].GetValue(t,null)));\r\n            }\r\n\r\n            return args;\r\n        }\r\n\r\n    }\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>public class DataBaseUntity { \/\/\u83b7\u53d6\u6570\u636e\u5e93\u6570\u636e\uff1a\u636e\u6570\u636e\u5e93\u7684\u8868\u5b57\u6bb5\u4e3a\u5b9e\u4f53\u7c7b\u76f8\u540c\u540d [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-503","post","type-post","status-publish","format-standard","hentry","category-14"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=503"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}