-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query: FromSql not composing with LINQ when it contains certain whitespace patterns #7005
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Milestone
Comments
Can you share a complete code listing (or project) that we can run to see the issue? We need to know what the various properties etc. in the model are to work out why this is being client evaluated. |
@rowanmiller Entities: public class Role
{
public int RoleId { get; set; }
public string Title { get; set; }
public string Parents { get; set; }
}
public enum PermissionEntity
{
AttachmentCollection = 1,
Category = 3,
}
public class Permission
{
public int PermissionId { get; set; }
public PermissionEntity Entity { get; set; }
public int RoleId { get; set; }
public int EntityId { get; set; }
} DbContext: public class EfContext : DbContext
{
string connectionString;
public EfContext(string connectionString) : base()
{
this.connectionString = connectionString;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Role>();
modelBuilder.Entity<Permission>();
}
} connection string <add name="TestContext" connectionString="Data Source=.;Initial Catalog=EFTestDB;Integrated Security = true;" providerName="System.Data.SqlClient" /> LINQ query: string cnn = ConfigurationManager.ConnectionStrings["TestContext"].ConnectionString;
int roleId = 77;
using (EfContext context = new EfContext(cnn))
{
var result = context.Set<Permission>()
.FromSql($@"
select
p.*
from Permission p
inner join
(
select
r.RoleId
from
Role r
where
Parents.exist('//I[.=sql:variable(""{{0}}"")]') = 1
union all
select {{0}} RoleId
) roles
on p.RoleId = roles.RoleId
", roleId)
.Where(c =>
c.Entity == PermissionEntity.AttachmentCollection &&
c.RoleId == roleId &&
c.EntityId == 22)
.ToList();
} Tables: CREATE TABLE [dbo].[Permission](
[PermissionId] [int] IDENTITY(1,1) NOT NULL,
[Entity] [int] NOT NULL,
[RoleId] [int] NOT NULL,
[EntityId] [int] NOT NULL,
CONSTRAINT [PK_Permission] PRIMARY KEY CLUSTERED
(
[PermissionId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[Role](
[RoleId] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](250) NOT NULL,
[Parents] [xml] NULL,
CONSTRAINT [PK_Role] PRIMARY KEY CLUSTERED
(
[RoleId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] |
Query composition did not work because the Sql started with new line character and there is no space after Select. 😞 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
type-bug
Hi
Following
FromSql
query does not compose with LINQ. No exception is raised and the result is correct BUTSql Server Profiler
shows thatWhere
clause is not composing withFromSql
query.but the query in
Sql Server Profiler
is:which shows
Where
clause is not included in queryEF Core version:1.0.1
Operating system: windows 10
Visual Studio version: vs 2015
The text was updated successfully, but these errors were encountered: