I am learning Document Databases, and we are using Marten/Linq in Visual Studio. The database is running through Postgres/PGAdmin. My database is football(not American) leagues, teams, players and managers. I am trying to construct queries based on multiple parameters. I have singular parameters down pretty well.
List<Player> englishPlayers = finalDb.Query<Player>().Where(x => x.Nationality.Contains("English")).ToList();
This query would create a list of all players whose Nationality is set to "English" in the Document Database.
Player is my class/table with a Nationality "field". What I am trying to do is query based on multiple parameters. For instance, I have multiple "fields" that are either an int or bool. As an example, if I wanted to create a query to show all players of a certain Nationality with lifetimeGoals > 100, how would I accomplish this?
I have searched Google for about an hour, and read through the suggested similar questions, but most of those questions don't account for Marten being used.
I've tried breaking it down by individual queries first and then combine them, for instance:
Player m4 = finalDb.Query<Player>().SelectMany(e => e.lifetimeGoals
.Where(p => e.lifetimeGoals >= 0));
However, this throws an error stating
int does not contain a definition for where, and no extension method 'Where' accepting a first argument of type 'int'.
My terminology with this is a little off, but hopefully this is clear enough to find guidance.
Class for Player:
class Player
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string Team { get; set; }
public string prefPosition { get; set; }
public string Nationality { get; set; }
public int yearsAtCurrentClub { get; set; }
public int lifetimeGoals { get; set; }
public int domesticTitles { get; set; }
public int europeanTitles { get; set; }
}//Class Player
Main class
static void Main(string[] args)
{
string connectionString = ConfigurationManager.ConnectionStrings
["FinalProjectDB"].ConnectionString;
IDocumentStore store = DocumentStore.For(connectionString);
using (var finalDb = store.OpenSession())
{
Player m4 = finalDb.Query<Player>().SelectMany(p => p.lifetimeGoals)
.Where(p => p.lifetimeGoals >= 0 && p.myString.Equals("valueToCheck"));
Console.ReadLine();
}