select top N number of rows in code behind.

select top N number of rows in code behind.

omerabbasi78omerabbasi78 Posts: 17Questions: 7Answers: 1
edited August 2017 in Free community support

Hi there,

I just need to know that how can I implement the following SQL query in data-tables.

Select Top 4 * from dbo.xyz where id = 9

In simple words, I want to know that how to select top N rows in Editor. I'm using .Net as back-end.

var response = new Editor(db, "tablename", pkey: "tId").Model<myModel>()
.Field(new Field("name").DbField("tablename.name"))
.Where("tablename.PropertyId", PropertyId, op: "=")
.Process(request)
.Data();

just add (top 4) in the above code.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    There is no option to do a TOP in the Editor SQL since it doesn't do ordering on the server-side. The top 4 would be effectively random based on how the database selects them. The ordering for the table's data is done on the client-side (unless server-side processing is used, but there still isn't a TOP option for that).

    If you aren't using editing functions, I would suggest you just query the database directly.

    Allan

  • omerabbasi78omerabbasi78 Posts: 17Questions: 7Answers: 1

    why cant I accept your answer?

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Looks like it was rejected. I've changed it now.

    Allan

This discussion has been closed.