Jaquarh
Jaquarh

Reputation: 6693

ASP.NET Using Entity Framework 5.X Class

I decided that constantly writing a long winded code to select data from a table was a bad method to use when I am constantly having to reference between tables, therefore I decided to write a class that handles the queries for me and returns the rows.

public Database(object query, object name)
{
    var tbl = (from c in db.name where query select c).ToArray();
    return tbl;
}

I am sort of new to Entity and am having a hard time trying to understand the type name should be.

At first I tried object which gave me this error:

'Model.Container' does not contain a definition for 'name' and no extension method 'name' accepting a first argument of type 'Model.rkdb_07022016Entities2' could be found (are you missing a using directive or an assembly reference?)

So I knew that the table name I am selecting from cannot be passed through as type object.

I took an educated guess and tried to make name type Queryable but still no luck.

Could anyone possibly point me in the right direction and add some references where I can maybe learn how to tackle these situations in the future?

Thank-you.

Upvotes: 1

Views: 38

Answers (1)

NDJ
NDJ

Reputation: 5194

(putting as an answer for future viewers) You probably want an Expression<Func<EntityType, bool>> If you need to make it generic, you could build something with T.

As I said in the comment, it's worth taking a look at Joseph Albahari's PredicateBuilder for sample code (or indeed use it as it is powerful)

Upvotes: 1

Related Questions