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

Commit 99915a8

Browse files
committed
Fix for #132. Removed arrays from automatic conversion.
# Conflicts: # Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs
1 parent ebd615c commit 99915a8

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

Source/LinqToDB.EntityFrameworkCore/LinqToDBForEFToolsImplDefault.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ public virtual void DefineConvertors(
450450
if (modelType.IsEnum)
451451
continue;
452452

453+
// skipping arrays
454+
if (modelType.IsArray)
455+
continue;
456+
453457
MapEFCoreType(modelType);
454458
if (modelType.IsValueType && !typeof(Nullable<>).IsSameOrParentOf(modelType))
455459
MapEFCoreType(typeof(Nullable<>).MakeGenericType(modelType));
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities
5+
{
6+
public class EntityWithArrays
7+
{
8+
[Key]
9+
public int Id { get; set; }
10+
11+
public Guid[] Guids { get; set; } = null!;
12+
}
13+
}

Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/Models/NpgSqlEntities/NpgSqlEnititesContext.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
2020
entity.HasNoKey();
2121
entity.ToView("EventsView", "views");
2222
});
23+
24+
modelBuilder.Entity<EntityWithArrays>(entity =>
25+
{
26+
});
2327
}
2428

2529
public virtual DbSet<Event> Events { get; set; } = null!;
30+
public virtual DbSet<EntityWithArrays> EntityWithArrays { get; set; } = null!;
2631

2732
}
2833
}

Tests/LinqToDB.EntityFrameworkCore.PostgreSQL.Tests/NpgSqlTests.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Linq;
3+
using FluentAssertions;
34
using LinqToDB.Data;
5+
using LinqToDB.DataProvider.PostgreSQL;
46
using LinqToDB.EntityFrameworkCore.BaseTests;
57
using LinqToDB.EntityFrameworkCore.PostgreSQL.Tests.Models.NpgSqlEntities;
68
using Microsoft.EntityFrameworkCore;
@@ -54,6 +56,35 @@ public void TestFunctionsMapping()
5456
}
5557
}
5658

57-
59+
[Test]
60+
public void TestViewMapping()
61+
{
62+
using (var db = CreateNpgSqlEntitiesContext())
63+
{
64+
var query = db.Set<EventView>().Where(e =>
65+
e.Name.StartsWith("any"));
66+
67+
var efResult = query.ToArray();
68+
var l2dbResult = query.ToLinqToDB().ToArray();
69+
}
70+
}
71+
72+
[Test]
73+
public void TestArray()
74+
{
75+
using (var db = CreateNpgSqlEntitiesContext())
76+
{
77+
var guids = new Guid[] { Guid.Parse("271425b1-ebe8-400d-b71d-a6e47a460ae3"),
78+
Guid.Parse("b75de94e-6d7b-4c70-bfa1-f8639a6a5b35") };
79+
80+
var query =
81+
from m in db.EntityWithArrays.ToLinqToDBTable()
82+
where Sql.Ext.PostgreSQL().Overlaps(m.Guids, guids)
83+
select m;
84+
85+
query.Invoking(q => q.ToArray()).Should().NotThrow();
86+
}
87+
}
88+
5889
}
5990
}

0 commit comments

Comments
 (0)