OFFSET in LINQ to SQL [duplicate] - entity-framework

This question already has answers here:
Offset/Fetch based paging (Implementation) in EntityFramework (Using LINQ) for SQL Server 2008
(3 answers)
Closed 4 years ago.
I am using EF 6.0.0 in C# ASP.net MVC 4.
When I use Take(10) and Skip(30) in linq, in sql profiler I can see it as TOP 10 and "> 30" in where clause.
How to write linq such that I get
OFFSET 30 ROWS
FETCH NEXT 10 ROWS ONLY
Thanks.

Did you try to do something like this?
int skipRecords = 30;
int takeRecords = 10;
context.SomeEntities.Skip(() => skipRecords)
.Take(() => takeRecords)
.ToList();
If you use variables, sql query will be parameterized.

Related

I can't drop a database in PostgreSQL 11 [duplicate]

This question already has answers here:
In psql, why do some commands have no effect?
(2 answers)
Closed 3 years ago.
I have 5 databases which are shown below.
I am trying to drop test database by using "drop database test". But when i check list of databases than test database also shown in that list.
What should I do now?
How i can resolve this issue?
Yeah you are missing the semi-colon. When psql changes from = to - in the prompt, it means you haven’t finished the query.

Is it possible to use a for loop in postgresql (Function) [duplicate]

This question already has answers here:
Postgres FOR LOOP
(6 answers)
Closed 4 years ago.
Is it possible to use a for loop in postgresql (Function)
In a word - yes. The syntax is quite simple and straightforward:
FOR i IN 1..10 LOOP
-- Do something with i
END LOOP;
You can also go backwards (by using the REVERSE keyword before specifying the range) and control the size of the step by using a BY clause.
See the documentation for the complete details.

how to change character length in execute file for postgresql [duplicate]

This question already has answers here:
pgAdmin: How to see complete value in a cell in output
(1 answer)
pgAdmin III faulty behavior?
(2 answers)
Closed 5 years ago.
I have a view in my database (PostgreSQL) and I would like to see it's code.
I wrote this query:
select definition from pg_views where viewname='x'
this works most of the time, However in some of the views when the select code is long I get at some point (...)
for example this is one of the results of query where it shows (...):
" SELECT f.selectid,
a.clientid,
a.orderid,
a.clientname,
c.part,
c.product,
c.okey,
e.contry,
d.city,
(
CASE
WHEN (b.dateofissue IS NULL) THEN
CASE
(...)"
This is only part of the code... Why it doesn't show me the whole code?
In pgAdmin III, under Query tool options:
pgAdmin Query tool Options
You want pg_get_viewdef, but I suspect you'll have the same issue there. The problem is probably that the client application is truncating the returned query.
If you're using PgAdmin-III this is in the FAQ.
If you're using psql this shouldn't happen.

How to get the next Sequence number in Sql Server Express using Entity Framework?

Now that Sql Server 2012 (including SQL Server Express 2012) has SEQUENCE feature just like Oracle as explained here, here, and here.
I can get the next sequence like so, SELECT NEXT VALUE FOR SeqName
But how do I do that from my code using Entity Framework 5?
I got it working using SqlQuery like so..
int sequence = context.Database.SqlQuery<int>("SELECT NEXT VALUE FOR MySequenceName").FirstOrDefault();

EntityFramework how to: select Max(Column), Count(*) from Table [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Get sum of two columns in one LINQ query without grouping
how to select Max and Count in one call using EF?
Select Max([Column]), Count(*) from [Table]
I think you can fake it grouping by 0. SQL Server will see through that constant group-by and eliminate it. It has no runtime cost.
The question is: Will EF translate this to SQL properly? Given the track record (in contrast to good old trusty LINQ to SQL!) this is in doubt.