Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 334d4e4

Browse files
committed
2 parents 07bb922 + f8dc822 commit 334d4e4

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
157157
.FirstOrDefault(v => CompareProperty(v.p, memberInfo))?.index ?? 0;
158158
}
159159

160+
var isIdentity = prop.GetAnnotations()
161+
.Any(a => a.Name.EndsWith(":ValueGenerationStrategy") && a.Value?.ToString() == "IdentityColumn");
162+
160163
var storeObjectId = GetStoreObjectIdentifier(et);
161164

162165
return new T[]{(T)(Attribute) new ColumnAttribute
@@ -167,7 +170,7 @@ public T[] GetAttributes<T>(Type type, MemberInfo memberInfo, bool inherit = tru
167170
DbType = prop.GetColumnType(),
168171
IsPrimaryKey = isPrimaryKey,
169172
PrimaryKeyOrder = primaryKeyOrder,
170-
IsIdentity = prop.ValueGenerated == ValueGenerated.OnAdd,
173+
IsIdentity = isIdentity,
171174
}};
172175
}
173176
}

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ public static bool IsQueryable(MethodCallExpression method, bool enumerable = tr
622622
{
623623
var type = method.Method.DeclaringType;
624624

625-
return type == typeof(Queryable) || (enumerable && type == typeof(Enumerable)) || type == typeof(LinqExtensions) ||
625+
return type == typeof(Queryable) || (enumerable && type == typeof(Enumerable)) || type == typeof(LinqExtensions) ||
626+
type == typeof(DataExtensions) || type == typeof(TableExtensions) ||
626627
type == typeof(EntityFrameworkQueryableExtensions);
627628
}
628629

@@ -771,7 +772,7 @@ TransformInfo LocalTransform(Expression e)
771772
{
772773
case ExpressionType.Constant:
773774
{
774-
if (typeof(EntityQueryable<>).IsSameOrParentOf(e.Type) || typeof(DbSet<>).IsSameOrParentOf(e.Type))
775+
if (typeof(EntityQueryable<>).IsSameOrParentOf(e.Type) || typeof(DbSet<>).IsSameOrParentOf(e.Type) || typeof(DbSet<>).IsSameOrParentOf(e.Type))
775776
{
776777
var entityType = e.Type.GenericTypeArguments[0];
777778
var newExpr = Expression.Call(null, Methods.LinqToDB.GetTable.MakeGenericMethod(entityType), Expression.Constant(dc));
@@ -881,6 +882,16 @@ TransformInfo LocalTransform(Expression e)
881882
break;
882883
}
883884

885+
if (typeof(ITable<>).IsSameOrParentOf(methodCall.Type))
886+
{
887+
if (generic.Name == "ToLinqToDBTable")
888+
{
889+
return new TransformInfo(methodCall.Arguments[0], false, true);
890+
}
891+
892+
break;
893+
}
894+
884895
if (typeof(IQueryable<>).IsSameOrParentOf(methodCall.Type))
885896
{
886897
// Invoking function to evaluate EF's Subquery located in function

Tests/LinqToDB.EntityFrameworkCore.SqlServer.Tests/ToolsTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,19 @@ public async Task TestUpdateAsync([Values(true, false)] bool enableFilter)
801801
}
802802
}
803803

804+
[Test]
805+
public void TestCreateTempTable([Values(true, false)] bool enableFilter)
806+
{
807+
using (var ctx = CreateContext(enableFilter))
808+
{
809+
using var db = ctx.CreateLinqToDbContext();
810+
using var temp = db.CreateTempTable(ctx.Employees, "#TestEmployees");
811+
812+
Assert.AreEqual(ctx.Employees.Count(), temp.Count());
813+
}
814+
}
815+
816+
804817
[Test]
805818
public void TestCommandTimeout()
806819
{

0 commit comments

Comments
 (0)