1

I've been trying to use SqlKata for a little while now and I'm really confused on how to get a single and simple WHERE clause to work.

I've been doing it as so:

var sistemas = DatabaseHelper.factory.Query("tblSistema").Where("id_fornecedor", fornc.id); it returns me an XQuery and I have no idea on how to execute it. Note that appending First() and Get() at the end throws an exception. 'sistemas.Get()' threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException'

I simply want to SELECT * FROM tblSistema WHERE id_fornecedor=1 for example

  • "Note that appending First() and Get() at the end throws an exception." which error? – MindSwipe Apr 01 '19 at 13:53
  • 'sistemas.Get()' threw an exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' – Matheus Souza Apr 01 '19 at 13:57
  • This should really be part of the question, why don't you [edit](https://stackoverflow.com/posts/55456664/edit) it? – MindSwipe Apr 01 '19 at 14:00
  • After short googling I found [this](https://stackoverflow.com/a/6309165/9363973) SO answer relating to your exception. Is it possible that you are passing a dynamic object to another assembly, or something along that line? – MindSwipe Apr 01 '19 at 14:05
  • If you hard code a 1 in there instead of `fornc.id` do you still get the exception? – bep Aug 19 '19 at 19:25

2 Answers2

1

First() execute the XQuery and returns the first record only of type dynamic in your case, internally it applies Limit(1) under the hood.

var book = db.Query("Books").Where("Id", 1).First();

Get() execute the XQuery and returns a List<dynamic>

var books = db.Query("Books").Where("Lang", "en").Get();

check more on https://sqlkata.com/docs/execution/setup#queryfactory

amd
  • 20,637
  • 6
  • 49
  • 67
1
var sistemas = DB.Query("tblSistema").Select("*").Where("id_fornecedor", fornc.id);

You can also do:

var sistemas = DB.Query("tblSistema").Select("*").Where("id_fornecedor", "=", fornc.id);

The operator is optional. = is the default.

And if you want to do certain selects, you would do:

var sistemas = DB.Query("tblSistema").Select("tblSistema.id_fornecedor", "tblSistem.blahSelect").Where("id_fornecedor", "=", fornc.id);
ejderuby
  • 710
  • 5
  • 21
Break008
  • 21
  • 5