我们现有的项目没有采用任何ORM,所有的数据读取与操作都是基于存储过程的,在代码端使用 Enterprise Library 5 。 在 EntLib 和数据库之间,是基于我原来写的一个 T4 实体生成的模板,之前也没有详细的去整,反正能运行出结果就行了,总之,代码很乱。
4 ^+ ^* O9 h! I+ _8 {! @6 H 最近一期项目告一段落,后续项目还没有上马,一手把这个部门建立起来的总监(经理)又离开了这个团队,我们几个老一批的员工也在思索着是否换换。趁着这个便当,我把这个东西在整出来,算是给我增加一个砝码吧。
) C# e. C* u6 N5 w. Z1 q 什么是 T4 模板,自己去搜吧,怎么用也请自己搜吧。懂就懂,不懂我也懒得解释。 z7 x$ `# |0 S. T9 {; \
我将要贴出的T4模板是将 SQLServer 2008 的 Table, View , TableType, Procedure 解析为 C# 里的对应实体,形如下:
8 d: G( j( T( d. ?+ N Table/View/TableType- f9 x* D0 c0 L8 g2 |) f% h
using System;
6 h" f3 a' `) {" E" J using System.Collections.Generic;
0 T! ]/ C9 q* P using System.Linq;
' w" }9 H% I+ a9 N' A using System.Text;. T; X) U: ]* t0 f
using System.Data;
# U K. C/ O) \/ E$ S using System.Collections;
# |! J% V! y5 g7 w' i" X/ h2 N using System.ComponentModel;
7 }+ k9 L; c( }, H using System.Runtime.Serialization;' q ~# V9 {$ L W& \2 ?/ a
namespace AsNum.MySecret.Entity.Database {" K* x7 i/ n$ q6 v% r! X O" X, r# A
///
, J) w0 ]2 m0 o, i/ |+ q2 B) B9 m5 C /// Table : dbo.LoginPolicy
4 h" r8 T& w+ p/ }. X /// 登陆策略
7 p9 u" Z2 p' N8 r% X% _7 @, Q /// 数据实体$ U. L6 Q4 C0 i( i: @
///
$ N/ d- ]' ?; p% _) r+ ^2 f; R9 e [Serializable]
9 M$ N- Q8 Y5 n. p) P [DataContract]5 H6 b6 _" C* a6 e& |; v! \
public class LoginPolicyEntity {
+ A+ h0 L: i; ~% Q* p /// 0 f O# m$ x0 F2 R* U8 P$ y$ P) k
/// 自动编号
* O& @4 p1 c/ K2 W4 X /// dbo.LoginPolicy.PolicyID
3 M2 P0 R1 @# W" t% f /// 默认值
7 ~. J) s7 x/ v4 C ///
$ Y/ B+ T' U, G% O public int PolicyID{
. n4 S; z" A" n/ P get;set;
- J2 f4 W6 v! a4 L- d }/ p7 n5 | j6 s; o" o% O8 G
private int _UnfreezeTime = 30;
' L/ U% }7 p; Y2 o) z2 y% D ///
+ d% C+ g" S: y4 R /// 解冻时间
- v: ^3 B$ r6 D. s /// dbo.LoginPolicy.UnfreezeTime. d, Y# C2 I: `
/// 默认值((30))
( V. Z: U3 Z* |9 s: n5 T0 {" L ///
9 N/ x& [( m( f3 `. J public int UnfreezeTime{
1 y. I |3 q( W0 T4 {( C: U4 ] m* R. p get{
: M# L+ j C$ v! ^8 [+ } return _UnfreezeTime;
) O% \: Y5 l1 v* j, Z5 b }
' B+ F! h, D5 w9 t3 D set{. {5 J9 n; c3 Y3 E9 ^8 }
_UnfreezeTime = value;
6 H* P& _7 O3 T3 Z }
6 L' C% \5 R: i2 }, V+ c7 @2 E }) Q6 v% y% K9 ]2 ?2 Z
private int _MaxFailedCount = 5;- Z) a: s% h1 g# n0 ?" r9 w M. s
/// % H( K' Y+ [3 O1 l- \0 ]
/// 最大失败次数
' [3 d" v) e) d4 d3 f% p: s) t- j /// dbo.LoginPolicy.MaxFailedCount# B4 a% p+ {6 ~9 t. ?0 N
/// 默认值((5))" I+ J0 b a2 R# O5 j% W: B
///
5 a5 @- _) A% e" y( f public int MaxFailedCount{4 n- t! t r0 e4 `5 f
get{& F0 f# W0 f0 _; h0 z$ i* E
return _MaxFailedCount;' M Y! b) p; @# ]/ g m8 n
}
. \; e4 G% ^5 V8 F3 m r: Z' ~) \ set{ F" `" y0 k7 F; _
_MaxFailedCount = value;( ~- @6 }" B' Q6 `7 u0 V2 U
}' `- Z; c' |# V- r
} |