Skip to content

Commit d8773e1

Browse files
committed
closes #29
1 parent 51b123f commit d8773e1

File tree

8 files changed

+116
-6
lines changed

8 files changed

+116
-6
lines changed

build/GlobalAssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
[assembly: AssemblyVersion("2.2.0")]
2121
[assembly: AssemblyFileVersion("2.2.0.0")]
22-
[assembly: AssemblyInformationalVersion("2.2.0-preview2")]
22+
[assembly: AssemblyInformationalVersion("2.2.0-preview5")]

msbuild/EFCore.Jet.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1010
<description>Allows Jet (Microsoft Access mdb or accdb format files) to be used with Entity Framework Core</description>
1111
<summary>Allows Jet (Microsoft Access mdb or accdb format files) to be used with Entity Framework Core</summary>
12-
<releaseNotes>for EF Core 2.1</releaseNotes>
12+
<releaseNotes>for EF Core 2.2</releaseNotes>
1313
<dependencies>
1414
<group targetFramework="net461">
15-
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="2.1.0" />
15+
<dependency id="Microsoft.EntityFrameworkCore.Relational" version="2.2.0" />
1616
</group>
1717
</dependencies>
1818
</metadata>

src/System.Data.Jet/JetCommand.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Data.Common;
44
using System.Data.Jet.JetStoreSchemaDefinition;
55
using System.Data.OleDb;
6-
using System.Diagnostics;
76
using System.Linq;
87
using System.Text.RegularExpressions;
98

@@ -20,7 +19,7 @@ public class JetCommand : DbCommand, ICloneable
2019
private int? _rowCount = null;
2120

2221
private static readonly Regex _skipRegularExpression = new Regex(@"\bskip\s(?<stringSkipCount>@.*)\b", RegexOptions.IgnoreCase);
23-
private static readonly Regex _selectRowCountRegularExpression = new Regex(@"^\s*select\s*@@rowcount\s*$", RegexOptions.IgnoreCase);
22+
private static readonly Regex _selectRowCountRegularExpression = new Regex(@"^\s*select\s*@@rowcount\s*[;]?\s*$", RegexOptions.IgnoreCase);
2423
private static readonly Regex _ifStatementRegex = new Regex(@"^\s*if\s*(?<not>not)?\s*exists\s*\((?<sqlCheckCommand>.+)\)\s*then\s*(?<sqlCommand>.*)$", RegexOptions.IgnoreCase);
2524

2625
/// <summary>
@@ -277,7 +276,6 @@ private DbDataReader TryGetDataReaderForSelectRowCount(string commandText)
277276
return null;
278277
}
279278

280-
281279
/// <summary>
282280
/// Executes the non query.
283281
/// </summary>
@@ -310,6 +308,13 @@ public override int ExecuteNonQuery()
310308
for (int i = 0; i < commandTextList.Length; i++)
311309
{
312310
string commandText = commandTextList[i];
311+
if (_selectRowCountRegularExpression.Match(commandText).Success)
312+
{
313+
if (_rowCount == null)
314+
throw new InvalidOperationException("Invalid " + commandText + ". Run a DataReader before.");
315+
returnValue = _rowCount.Value;
316+
continue;
317+
}
313318
commandText = ParseIdentity(commandText);
314319
commandText = ParseGuid(commandText);
315320

@@ -386,8 +391,10 @@ private JetDataReader InternalExecuteDbDataReader(string commandText, CommandBeh
386391
private int InternalExecuteNonQuery(string commandText)
387392
{
388393

394+
// ReSharper disable NotAccessedVariable
389395
int topCount;
390396
int skipCount;
397+
// ReSharper restore NotAccessedVariable
391398
string newCommandText;
392399
if (!CheckExists(commandText, out newCommandText))
393400
return 0;

test/EFCore.Jet.Integration.Test/EFCore.Jet.Integration.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,16 @@
241241
<Compile Include="GearOfWar\Model\Squad.cs" />
242242
<Compile Include="GearOfWar\Model\SquadMission.cs" />
243243
<Compile Include="GearOfWar\Model\Weapon.cs" />
244+
<Compile Include="Model78_MigrationUpdate\Context.cs" />
245+
<Compile Include="Model78_MigrationUpdate\Student.cs" />
244246
<Compile Include="Model04\SqlCeTest.cs" />
245247
<Compile Include="Model16_OwnCollection\SqLiteTest.cs" />
246248
<Compile Include="Model16_OwnCollection\SqlCeTest.cs" />
247249
<Compile Include="Model16_OwnCollection\SqlServerTest.cs" />
248250
<Compile Include="Model76_FullCreate\SqlServerTest.cs" />
249251
<Compile Include="Model76_FullCreate\SqlCeTest.cs" />
250252
<Compile Include="Model77_DateTimeOffset\SqlCeTest.cs" />
253+
<Compile Include="Model78_MigrationUpdate\Test.cs" />
251254
<Compile Include="Model_MainTests\Context.cs" />
252255
<Compile Include="Model_MainTests\SqlServerTest.cs" />
253256
<Compile Include="Model_MainTests\SqlCeTest.cs" />
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Data.Common;
3+
using EntityFrameworkCore.Jet;
4+
using Microsoft.EntityFrameworkCore;
5+
6+
namespace EFCore.Jet.Integration.Test.Model78_MigrationUpdate
7+
{
8+
public class Context : DbContext
9+
{
10+
11+
public Context(DbConnection connection) :
12+
base(new DbContextOptionsBuilder().UseJet(connection, _ => _.MigrationsAssembly(typeof(Context).Assembly.GetName().Name)).Options)
13+
{
14+
TestBase<Context>.TryCreateTables(this);
15+
}
16+
17+
public DbSet<Student> Students { get; set; }
18+
19+
protected override void OnModelCreating(ModelBuilder modelBuilder)
20+
{
21+
base.OnModelCreating(modelBuilder);
22+
modelBuilder.Entity<Student>().HasIndex(_ => _.StudentName);
23+
}
24+
}
25+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
using System.ComponentModel.DataAnnotations.Schema;
4+
5+
namespace EFCore.Jet.Integration.Test.Model78_MigrationUpdate
6+
{
7+
[Table("Students_78")]
8+
public class Student
9+
{
10+
public int StudentId { get; set; }
11+
12+
[Required]
13+
[MaxLength(50)]
14+
// Index are supported only with fluent API
15+
/*[Index]*/
16+
public string StudentName { get; set; }
17+
18+
public string Notes { get; set; }
19+
20+
public override string ToString()
21+
{
22+
return string.Format("{2}: {0} - {1}", StudentId, StudentName, base.ToString());
23+
}
24+
}
25+
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Data.Common;
3+
using System.Data.Jet;
4+
using System.Data.OleDb;
5+
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
8+
namespace EFCore.Jet.Integration.Test.Model78_MigrationUpdate
9+
{
10+
[TestClass]
11+
public class Test
12+
{
13+
14+
protected DbConnection GetConnection()
15+
{
16+
// ReSharper disable once CollectionNeverUpdated.Local
17+
18+
OleDbConnectionStringBuilder oleDbConnectionStringBuilder = new OleDbConnectionStringBuilder();
19+
//oleDbConnectionStringBuilder.Provider = "Microsoft.Jet.OLEDB.4.0";
20+
//oleDbConnectionStringBuilder.DataSource = @".\Empty.mdb";
21+
oleDbConnectionStringBuilder.Provider = "Microsoft.ACE.OLEDB.15.0";
22+
oleDbConnectionStringBuilder.DataSource = Helpers.GetTestDirectory() + "\\Model78_MigrationUpdateJet.accdb";
23+
return new JetConnection(oleDbConnectionStringBuilder.ToString());
24+
}
25+
26+
[TestMethod]
27+
public void MigrationUpdateTest()
28+
{
29+
using (DbConnection connection = GetConnection())
30+
{
31+
using (var context = new Context(connection))
32+
{
33+
string sql = @"
34+
UPDATE[Students_78] SET [StudentName] = '2'
35+
WHERE[StudentId] = 1;
36+
SELECT @@ROWCOUNT; ";
37+
context.Database.ExecuteSqlCommand(sql);
38+
}
39+
}
40+
}
41+
42+
}
43+
}

test/EFCore.Jet.Integration.Test/TestBase`.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.Data.Sqlite;
99
using Microsoft.EntityFrameworkCore;
1010
using Microsoft.EntityFrameworkCore.Infrastructure;
11+
using Microsoft.EntityFrameworkCore.Migrations;
1112
using Microsoft.EntityFrameworkCore.Storage;
1213
using Microsoft.VisualStudio.TestTools.UnitTesting;
1314

@@ -90,6 +91,11 @@ private static RelationalDatabaseCreator GetDatabaseCreatorService(T context)
9091
return databaseCreator;
9192
}
9293

94+
public static IMigrator GetDatabaseMigratorService(T context)
95+
{
96+
return context.GetService<IMigrator>();
97+
}
98+
9399
private static string GetFullExceptionStackMessages(Exception ex)
94100
{
95101
if (ex == null)

0 commit comments

Comments
 (0)