|
13 | 13 |
|
14 | 14 | namespace MyStaging.xUnitTest.DAL |
15 | 15 | { |
16 | | - public partial class Article : QueryContext<ArticleModel> |
17 | | - { |
18 | | - public static Article Context { get { return new Article(); } } |
| 16 | + public partial class Article : QueryContext<ArticleModel> |
| 17 | + { |
| 18 | + public static Article Context { get { return new Article(); } } |
19 | 19 |
|
20 | | - public static InsertBuilder<ArticleModel> InsertBuilder => new InsertBuilder<ArticleModel>(ArticleSchema.Instance); |
21 | | - public static ArticleModel Insert(ArticleModel model) => InsertBuilder.Insert(model); |
22 | | - public static int InsertRange(List<ArticleModel> models) => InsertBuilder.InsertRange(models).SaveChange(); |
| 20 | + public static InsertBuilder<ArticleModel> InsertBuilder => new InsertBuilder<ArticleModel>(ArticleSchema.Instance); |
| 21 | + public static ArticleModel Insert(ArticleModel model) => InsertBuilder.Insert(model); |
| 22 | + public static int InsertRange(List<ArticleModel> models) => InsertBuilder.InsertRange(models).SaveChange(); |
23 | 23 |
|
24 | | - public static DeleteBuilder<ArticleModel> DeleteBuilder => new DeleteBuilder<ArticleModel>(); |
25 | | - public static int Delete(string id,string userid) => DeleteBuilder.Where(f => f.Id == id && f.Userid == userid).SaveChange(); |
| 24 | + public static DeleteBuilder<ArticleModel> DeleteBuilder => new DeleteBuilder<ArticleModel>(); |
| 25 | + public static int Delete(string id, string userid) |
| 26 | + { |
| 27 | + var affrows = DeleteBuilder.Where(f => f.Id == id && f.Userid == userid).SaveChange(); |
| 28 | + if (affrows > 0) Helpers.PgSqlHelper.CacheManager?.RemoveItemCache<ArticleModel>(id); |
| 29 | + return affrows; |
| 30 | + } |
26 | 31 |
|
27 | | - public static ArticleUpdateBuilder UpdateBuilder => new ArticleUpdateBuilder(); |
28 | | - public static ArticleUpdateBuilder Update(string id,string userid) |
29 | | - { |
30 | | - return new ArticleUpdateBuilder(null, id,userid); |
31 | | - } |
| 32 | + public static ArticleUpdateBuilder UpdateBuilder => new ArticleUpdateBuilder(); |
| 33 | + public static ArticleUpdateBuilder Update(string id, string userid) |
| 34 | + { |
| 35 | + return new ArticleUpdateBuilder(null, id, userid); |
| 36 | + } |
32 | 37 |
|
33 | | - public class ArticleUpdateBuilder : UpdateBuilder<ArticleModel> |
34 | | - { |
35 | | - public ArticleUpdateBuilder(string id,string userid) |
36 | | - { |
37 | | - base.Where(f => f.Id == id && f.Userid == userid); |
38 | | - } |
| 38 | + public class ArticleUpdateBuilder : UpdateBuilder<ArticleModel> |
| 39 | + { |
| 40 | + public ArticleUpdateBuilder(string id, string userid) |
| 41 | + { |
| 42 | + base.Where(f => f.Id == id && f.Userid == userid); |
| 43 | + } |
39 | 44 |
|
40 | | - public ArticleUpdateBuilder(Action<ArticleModel> onChanged, string id,string userid) : base(onChanged) |
41 | | - { |
42 | | - base.Where(f => f.Id == id && f.Userid == userid); |
43 | | - } |
| 45 | + public ArticleUpdateBuilder(Action<ArticleModel> onChanged, string id, string userid) : base(onChanged) |
| 46 | + { |
| 47 | + base.Where(f => f.Id == id && f.Userid == userid); |
| 48 | + } |
44 | 49 |
|
45 | | - public ArticleUpdateBuilder() { } |
| 50 | + public ArticleUpdateBuilder() { } |
46 | 51 |
|
47 | | - public new ArticleUpdateBuilder Where(Expression<Func<ArticleModel, bool>> predicate) |
48 | | - { |
49 | | - base.Where(predicate); |
50 | | - return this; |
51 | | - } |
52 | | - public new ArticleUpdateBuilder Where(string formatCommad, params object[] pValue) |
53 | | - { |
54 | | - base.Where(formatCommad,pValue); |
55 | | - return this; |
56 | | - } |
57 | | - public ArticleUpdateBuilder SetId(string id) |
58 | | - { |
59 | | - base.SetField("id", NpgsqlDbType.Varchar, id, -1, null); |
60 | | - return this; |
61 | | - } |
62 | | - public ArticleUpdateBuilder SetUserid(string userid) |
63 | | - { |
64 | | - base.SetField("userid", NpgsqlDbType.Varchar, userid, -1, null); |
65 | | - return this; |
66 | | - } |
67 | | - public ArticleUpdateBuilder SetTitle(string title) |
68 | | - { |
69 | | - base.SetField("title", NpgsqlDbType.Varchar, title, 255, null); |
70 | | - return this; |
71 | | - } |
72 | | - public ArticleUpdateBuilder SetContent(JToken content) |
73 | | - { |
74 | | - base.SetField("content", NpgsqlDbType.Jsonb, content, -1, null); |
75 | | - return this; |
76 | | - } |
77 | | - public ArticleUpdateBuilder SetCreatetime(DateTime createtime) |
78 | | - { |
79 | | - base.SetField("createtime", NpgsqlDbType.Timestamp, createtime, 8, null); |
80 | | - return this; |
81 | | - } |
82 | | - } |
| 52 | + public new ArticleUpdateBuilder Where(Expression<Func<ArticleModel, bool>> predicate) |
| 53 | + { |
| 54 | + base.Where(predicate); |
| 55 | + return this; |
| 56 | + } |
| 57 | + public new ArticleUpdateBuilder Where(string formatCommad, params object[] pValue) |
| 58 | + { |
| 59 | + base.Where(formatCommad, pValue); |
| 60 | + return this; |
| 61 | + } |
| 62 | + public ArticleUpdateBuilder SetId(string id) |
| 63 | + { |
| 64 | + base.SetField("id", NpgsqlDbType.Varchar, id, -1, null); |
| 65 | + return this; |
| 66 | + } |
| 67 | + public ArticleUpdateBuilder SetUserid(string userid) |
| 68 | + { |
| 69 | + base.SetField("userid", NpgsqlDbType.Varchar, userid, -1, null); |
| 70 | + return this; |
| 71 | + } |
| 72 | + public ArticleUpdateBuilder SetTitle(string title) |
| 73 | + { |
| 74 | + base.SetField("title", NpgsqlDbType.Varchar, title, 255, null); |
| 75 | + return this; |
| 76 | + } |
| 77 | + public ArticleUpdateBuilder SetContent(JToken content) |
| 78 | + { |
| 79 | + base.SetField("content", NpgsqlDbType.Jsonb, content, -1, null); |
| 80 | + return this; |
| 81 | + } |
| 82 | + public ArticleUpdateBuilder SetCreatetime(DateTime createtime) |
| 83 | + { |
| 84 | + base.SetField("createtime", NpgsqlDbType.Timestamp, createtime, 8, null); |
| 85 | + return this; |
| 86 | + } |
| 87 | + } |
83 | 88 |
|
84 | | - } |
| 89 | + } |
85 | 90 | } |
0 commit comments