Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 7f0c7c3

Browse files
committed
Ignored Fields Selection feature
This feature allows the Ignored Fields to be populated if the result set has those ignored field listed in it.
1 parent d609840 commit 7f0c7c3

File tree

8 files changed

+691
-534
lines changed

8 files changed

+691
-534
lines changed

src/ServiceStack.OrmLite/Expressions/ReadExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ namespace ServiceStack.OrmLite
88
{
99
public static class ReadExtensions
1010
{
11-
public static SqlExpressionVisitor<T> CreateExpression<T>()
12-
{
13-
return OrmLiteConfig.DialectProvider.ExpressionVisitor<T>();
14-
}
11+
public static SqlExpressionVisitor<T> CreateExpression<T>()
12+
{
13+
return OrmLiteConfig.DialectProvider.ExpressionVisitor<T>();
14+
}
1515

1616
public static List<T> Select<T>(this IDbCommand dbCmd, Expression<Func<T, bool>> predicate)
1717
where T : new()
@@ -135,7 +135,7 @@ public static TKey GetScalar<T,TKey>(this IDbCommand dbCmd,Expression<Func<T, TK
135135
private static T ConvertTo<T>(IDataReader dataReader)
136136
where T : new()
137137
{
138-
var fieldDefs = ModelDefinition<T>.Definition.FieldDefinitionsArray;
138+
var fieldDefs = ModelDefinition<T>.Definition.AllFieldDefinitionsArray;
139139

140140
using (dataReader)
141141
{
@@ -166,7 +166,7 @@ private static T ConvertTo<T>(IDataReader dataReader)
166166
private static List<T> ConvertToList<T>(IDataReader dataReader)
167167
where T : new()
168168
{
169-
var fieldDefs = ModelDefinition<T>.Definition.FieldDefinitionsArray;
169+
var fieldDefs = ModelDefinition<T>.Definition.AllFieldDefinitionsArray;
170170
var fieldDefCache = new Dictionary<int, FieldDefinition>();
171171

172172
var to = new List<T>();
Lines changed: 116 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,117 @@
1-
//
2-
// ServiceStack.OrmLite: Light-weight POCO ORM for .NET and Mono
3-
//
4-
// Authors:
5-
// Demis Bellot ([email protected])
6-
//
7-
// Copyright 2010 Liquidbit Ltd.
8-
//
9-
// Licensed under the same terms of ServiceStack: new BSD license.
10-
//
11-
12-
using System;
13-
using System.Collections.Generic;
14-
using System.Linq;
15-
using ServiceStack.DataAnnotations;
16-
17-
namespace ServiceStack.OrmLite
18-
{
19-
public class ModelDefinition
20-
{
21-
public ModelDefinition()
22-
{
23-
this.FieldDefinitions = new List<FieldDefinition>();
24-
this.CompositeIndexes = new List<CompositeIndexAttribute>();
25-
}
26-
27-
public string Name { get; set; }
28-
29-
public string Alias { get; set; }
30-
31-
public string Schema { get; set; }
32-
33-
public bool IsInSchema { get { return this.Schema != null; } }
34-
35-
public string ModelName
36-
{
37-
get { return this.Alias ?? this.Name; }
38-
}
39-
40-
public Type ModelType { get; set; }
41-
42-
public string SqlSelectAllFromTable { get; set; }
43-
44-
public FieldDefinition PrimaryKey
45-
{
46-
get
47-
{
48-
return this.FieldDefinitions.First(x => x.IsPrimaryKey);
49-
}
50-
}
51-
52-
public List<FieldDefinition> FieldDefinitions { get; set; }
53-
54-
private FieldDefinition[] fieldDefinitionsArray;
55-
public FieldDefinition[] FieldDefinitionsArray
56-
{
57-
get
58-
{
59-
if (fieldDefinitionsArray == null)
60-
{
61-
fieldDefinitionsArray = FieldDefinitions.ToArray();
62-
}
63-
return fieldDefinitionsArray;
64-
}
65-
}
66-
67-
public List<CompositeIndexAttribute> CompositeIndexes { get; set; }
68-
}
69-
70-
71-
public static class ModelDefinition<T>
72-
{
73-
private static ModelDefinition definition;
74-
public static ModelDefinition Definition
75-
{
76-
get { return definition ?? (definition = typeof(T).GetModelDefinition()); }
77-
}
78-
79-
private static string primaryKeyName;
80-
public static string PrimaryKeyName
81-
{
82-
get { return primaryKeyName ?? (primaryKeyName = Definition.PrimaryKey.FieldName); }
83-
}
84-
85-
}
1+
//
2+
// ServiceStack.OrmLite: Light-weight POCO ORM for .NET and Mono
3+
//
4+
// Authors:
5+
// Demis Bellot ([email protected])
6+
//
7+
// Copyright 2010 Liquidbit Ltd.
8+
//
9+
// Licensed under the same terms of ServiceStack: new BSD license.
10+
//
11+
12+
using System;
13+
using System.Collections.Generic;
14+
using System.Linq;
15+
using ServiceStack.DataAnnotations;
16+
17+
namespace ServiceStack.OrmLite
18+
{
19+
public class ModelDefinition
20+
{
21+
public ModelDefinition()
22+
{
23+
this.FieldDefinitions = new List<FieldDefinition>();
24+
this.IgnoredFieldDefinitions = new List<FieldDefinition>();
25+
this.CompositeIndexes = new List<CompositeIndexAttribute>();
26+
}
27+
28+
public string Name { get; set; }
29+
30+
public string Alias { get; set; }
31+
32+
public string Schema { get; set; }
33+
34+
public bool IsInSchema { get { return this.Schema != null; } }
35+
36+
public string ModelName
37+
{
38+
get { return this.Alias ?? this.Name; }
39+
}
40+
41+
public Type ModelType { get; set; }
42+
43+
public string SqlSelectAllFromTable { get; set; }
44+
45+
public FieldDefinition PrimaryKey
46+
{
47+
get
48+
{
49+
return this.FieldDefinitions.First(x => x.IsPrimaryKey);
50+
}
51+
}
52+
53+
public List<FieldDefinition> FieldDefinitions { get; set; }
54+
55+
private FieldDefinition[] fieldDefinitionsArray;
56+
public FieldDefinition[] FieldDefinitionsArray
57+
{
58+
get
59+
{
60+
if (fieldDefinitionsArray == null)
61+
{
62+
fieldDefinitionsArray = FieldDefinitions.ToArray();
63+
}
64+
return fieldDefinitionsArray;
65+
}
66+
}
67+
68+
public List<FieldDefinition> IgnoredFieldDefinitions { get; set; }
69+
70+
private FieldDefinition[] ignoredFieldDefinitionsArray;
71+
public FieldDefinition[] IgnoredFieldDefinitionsArray
72+
{
73+
get
74+
{
75+
if (ignoredFieldDefinitionsArray == null)
76+
{
77+
ignoredFieldDefinitionsArray = IgnoredFieldDefinitions.ToArray();
78+
}
79+
return ignoredFieldDefinitionsArray;
80+
}
81+
}
82+
83+
private FieldDefinition[] allFieldDefinitionsArray;
84+
public FieldDefinition[] AllFieldDefinitionsArray
85+
{
86+
get
87+
{
88+
if (allFieldDefinitionsArray == null)
89+
{
90+
List<FieldDefinition> allItems = new List<FieldDefinition>(FieldDefinitions);
91+
allItems.AddRange(IgnoredFieldDefinitions);
92+
allFieldDefinitionsArray = allItems.ToArray();
93+
}
94+
return allFieldDefinitionsArray;
95+
}
96+
}
97+
98+
public List<CompositeIndexAttribute> CompositeIndexes { get; set; }
99+
}
100+
101+
102+
public static class ModelDefinition<T>
103+
{
104+
private static ModelDefinition definition;
105+
public static ModelDefinition Definition
106+
{
107+
get { return definition ?? (definition = typeof(T).GetModelDefinition()); }
108+
}
109+
110+
private static string primaryKeyName;
111+
public static string PrimaryKeyName
112+
{
113+
get { return primaryKeyName ?? (primaryKeyName = Definition.PrimaryKey.FieldName); }
114+
}
115+
116+
}
86117
}

0 commit comments

Comments
 (0)