This question already has answers here:
How to view LINQ Generated SQL statements?
(8 answers)
Get SQL code from an Entity Framework Core IQueryable<T>
(10 answers)
Closed 11 months ago.
I have a fairly simple LINQ query (using method syntax):
_context.Foo.Count(c => c.Bar > 123);
I need to see the SQL that will run against the database. I'm not using SQL Server, so I unfortunately can't use the SQL Server Profiler.
I'm unable to use query syntax in this case.
Is there any sort of .ToQueryString(); method?
Related
This question already has answers here:
How can I evaluate a C# expression dynamically?
(9 answers)
Closed 3 years ago.
So basically what i have been struggling with is to evaluate sentence in EF Core.
For example if i have:
string condition = "65 < 100 AND 65 > 50"
How can evaluate that?
You can execute SQL String in EF Core, So what you need is to write the whole SQL you want in a sctring and then concatenate this part to it. after that you execute it like this
myDbContextObject.Database.ExecuteSqlCommand(sqlString,params[]);
OR
myDbContextObject.Table.FromSql(sqlString,params[]);
This question already has answers here:
What does a timestamp in T-Sql mean in C#?
(4 answers)
Closed 4 years ago.
My client is using Insight.Database for SQL Server ORM, using C# as the client. I have encountered a SQL Server 2017 database datatype 'Timestamp' and I am unsure what the C# entity type should be? I have downloaded the code for the Insight.Database and have globally searched for Timestamp, but results are empty.
Any ideas what datatype in C# would best represent a SQL Server Timestamp datatype?
It would be a byte array as that's what you'd use for varbinary.
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql-server-data-type-mappings
This question already has an answer here:
LINQ - Query syntax vs method chains & lambda [closed]
(1 answer)
Closed 5 years ago.
In some cases I see LINQ written this way:
L.Select(_ => _.A).Where(...)
and in some other cases, I see this:
A = from B in C where (...)
Do these two syntaxes have different names?
I understand both, but they seem to be referred to as LINQ so I am a bit confused.
The first one is Method Syntax or Method extension syntax or Fluent
The second one is Query Syntax or Query Expression Syntax
This question already has answers here:
Using contains() in LINQ to SQL
(7 answers)
Closed 8 years ago.
I am trying to convert the following SQL statement to a Link2SQL statement.
SELECT * FROM Global.CustomData
WHERE CustomDataSource LIKE '%Plugin%'
I have converted it to this statement
var query =
from item in db.CustomDatas
where item.CustomDataSource.Contains(dataSource)
select item;
And have tried setting dataSource to the following: "Plugin", "%Plugin%", "/Plugin/" and "%/Plugin%/". These I have taken from other examples. Unfortunately, although the TSQL statement does return a value, I cannot get the Linq2Sql statement to return anything. Could someone tell me what I am doing wrong?
You should pass "Plugin", the only thing I can think of is the case sensitivity. Try something like this:
where item.CustomDataSource.ToLower().Contains(dataSource.ToLower())
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to use SQL user defined functions in .NET?
Say I have created a SQL Server function function1(int a,int b) in my database, now how can I call this function in MVC3 controller ?
You would use either ADO.NET or any one of many other database technologies.