I'm very new to C#. In other languages I'm used to work with DB in a way "prepare, then execute statement with needed parameters", so I could pass prepared query to function and do all such things. Now I'm trying to solve this task: get almost identicaly result sets from different databases in different contexts. Like you have "files" table with files metadata and in one DB it does have "file_priority" field, and in other DB it does have "file_description" field and so on, but most fields are common and processing logic are almost same.
So I wanted to prepare query in outer code and pass it along with needed param values to data-processing function (or class).
I can't find any example of executing (pass param values to query) linq2db query.
==========UPD============
Ok, example. Let's talk about Perl.
package main1;
use FileProcessor;
my $sth = $dbh->prepare(qq[ SELECT name, extension, file_priority FROM files WHERE file_id = ? ]);
my $processor = new FileProcessor(query => $sth);
my $file_id = $ENV{file_id};
my $file_data = $processor->get_file(id => $file_id);
package main2;
use FileProcessor;
my $sth = $dbh->prepare(qq[ SELECT name, extension, file_description FROM files WHERE file_id = ? ]); # preparing query
my $processor = new FileProcessor(query => $sth);
my $file_id = $ENV{file_id};
my $file_data = $processor->get_file(id => $file_id);
package FileProcessor;
sub new {
my $class = shift;
my $self = {@_};
bless $self, $class;
}
sub get_file {
my $self = shift;
my %params = @_;
$self->{query}->execute($params{$file_id}); #passing params to query
my $file_data = $self->{query}->fetchrow_hashref; # fetching result from DB
# do something with file data
# ...
return $file_data;
}