LINQ to SQL how to write a method that checks if a row exists when we have multiple tables
I am trying to write a method in C # that can take as parameter tabletype, column and column value and check if it got a row with a value with a value
the method looks like this:
public object GetRecordFromDatabase(Type tabletype, string columnname, string columnvalue)
I am using LINQ to SQL and need it in a generic way, so I don't have to write every table I get into the DB.
I've been doing this so far for every table, but over 70 of them get cumbersome and boring.
Is there a way to generate the following code dynamically and change the copied table names with values from the parameter list? In this example, I have a table in the DB called tbl_nation which DataContext pluralizes to tbl_nations and I check the column for the value
if (DB.tbl_nations.Count (c => c.code.Equals (columnvalue)) == 1)
{
return DB.tbl_nations.Single (c => c.code.Equals (columnvalue));
}
0
a source to share