1
+ using System ;
1
2
using System . Data ;
2
3
using System . Data . Common ;
3
4
using System . Text ;
4
5
using NHibernate . Dialect . Function ;
5
6
using NHibernate . Dialect . Schema ;
7
+ using NHibernate . SqlCommand ;
6
8
using NHibernate . Util ;
7
9
using Environment = NHibernate . Cfg . Environment ;
8
10
@@ -111,7 +113,7 @@ public override string SelectGUIDString
111
113
112
114
public override bool SupportsLimit
113
115
{
114
- get { return false ; }
116
+ get { return true ; }
115
117
}
116
118
117
119
public override bool SupportsLimitOffset
@@ -129,6 +131,17 @@ public override IDataBaseSchema GetDataBaseSchema(DbConnection connection)
129
131
return new MsSqlCeDataBaseSchema ( connection ) ;
130
132
}
131
133
134
+ public override SqlString GetLimitString ( SqlString querySqlString , SqlString offset , SqlString limit )
135
+ {
136
+ var top = new SqlStringBuilder ( )
137
+ . Add ( " top (" )
138
+ . Add ( limit )
139
+ . Add ( ")" )
140
+ . ToSqlString ( ) ;
141
+
142
+ return querySqlString . Insert ( GetAfterSelectInsertPoint ( querySqlString ) , top ) ;
143
+ }
144
+
132
145
public override string Qualify ( string catalog , string schema , string table )
133
146
{
134
147
// SQL Server Compact doesn't support Schemas. So join schema name and table name with underscores
@@ -174,5 +187,18 @@ public override string Qualify(string catalog, string schema, string table)
174
187
name = OpenQuote + name + CloseQuote ;
175
188
return qualifiedName . Append ( name ) . ToString ( ) ;
176
189
}
177
- }
190
+
191
+ private static int GetAfterSelectInsertPoint ( SqlString sql )
192
+ {
193
+ if ( sql . StartsWithCaseInsensitive ( "select distinct" ) )
194
+ {
195
+ return 15 ;
196
+ }
197
+ if ( sql . StartsWithCaseInsensitive ( "select" ) )
198
+ {
199
+ return 6 ;
200
+ }
201
+ throw new NotSupportedException ( "The query should start with 'SELECT' or 'SELECT DISTINCT'" ) ;
202
+ }
203
+ }
178
204
}
0 commit comments