score:3
Accepted answer
if you know t
will be of type ilookup
you need to put a constraint on it like such:
public interface ilookup
{
int id { get; set; }
string fr { get; set; }
string nl { get; set; }
string en { get; set; }
bool isactive { get; set; }
}
public class lookupa : ilookup
{
}
public class lookupb : ilookup
{
}
public interface ilookuprepository<t>
{
ilist<t> getlist();
}
public class lookuprepository<t> : ilookuprepository<t> where t : ilookup
{
public ilist<t> getlist()
{
list<t> list = session.query<t>().where(y => y.isactive).tolist<t>();
return list;
}
}
score:0
you should be able to leverage generic constraints to help you out.
first, change your interface definition:
public interface ilookuprepository<t> where t : ilookup
// ^^^^^^^^^^^^^^^^^
second, change your class definition to match the constraints:
public class lookuprepository<t> : ilookuprepository<t> where t : ilookup
// ^^^^^^^^^^^^^^^^^
the constraint will require the generic type parameter to implement ilookup
. this will let you use the interface members in your getlist
method.
Source: stackoverflow.com
Related Query
- Make a LINQ query on object implementing interface
- convert linq to object query to sql query (no linq to sql code or datacontext)
- Make NameValueCollection accessible to LINQ Query
- Iterate through properties and values of an object returned via a linq query on a domain model
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How to understand the following C# linq code of implementing the algorithm to return all combinations of k elements from n
- LINQ SQL query check if a object field is not null
- LINQ Query - How to map a resultset into another object using Select
- Linq query a List of objects containing a list of object
- Problem with LINQ to Entities query using Sum on child object property
- Is there any way to create a LINQ query as a variable without having the data source (yet)?
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- Creating a new object in LINQ query
- linq query anonymous type cannot be converted to POCO object
- LINQ Source Code Available
- How to call a method in the where clause of a LINQ query on a IQueryable object
- Query a collection using PropertyInfo object in LINQ
- want a Query to make order by variable in Linq query
- Check if object is Null in Linq Query
- Linq with where clause in many-to-many EF Code First object
- LINQ query on an object list to get distribution based on multiple fields
- Return Linq query results into List object
- linq - how do you do a query for items in one query source that are not in another one?
- How to call method/function in where clause of a LINQ query as IEnumerable object
- Linq to object dynamic query is it possible?
- How can I write the following code more elegantly using LINQ query syntax?
- LINQ query on object with unknown class
- LINQ to JSON - Query for object or an array
- Casting Linq Query Results to an Interface
More Query from same tag
- Replacing values in a list inside a Linq query with values from a dictionary
- Populating classes with many to many linq data
- Perform a LINQ query without using NotMapped properties in EF
- Order query Results by Enum Name
- Getting The query contains references do Elements defined in the context of other data Error
- Many to Many and Linq: updating relationships
- How to extract records which are between specified hours of the day in Entity Framework?
- How to get parent node in a tree structure like this
- ef core linq filtered child entities
- Combine Aggregate functions over multiple tables using Entity Framework
- Retrieving strongly typed Property names using Expression Trees
- Build composed C# Linq Where with multiple lambda expressions
- SQLite error no such column using Entity Framework
- List where Clause
- Dynamic Linq to Datatable Nullable Fields
- How to use a string[ ] list in a nested Select statement in WPF C# application
- LINQ Select on string results in char
- Linq group by in sum column from with where clause
- Dynamic selects in LINQ
- Need help with a simple Linq query running with Entity Framework 4
- How cani write Linq Query for getting Record over multipul times
- Finding maximum number of rows created per hour?
- Getting Stack Overflow when performing Linq to Sitecore Query
- Find Min and Max value in table between given variable in C#
- Linq result to ViewData and show result in PartialView
- full word match query: turning sql into linq
- Map array of strings to property in a List of objects C#
- Pure Speed for Lookup Single Value Type c#?
- Create linq query as string
- How to set a DB value to Nothing with Linq?