How do you cast a LinqToSql Table<TEntity> as a Table<IEntity> where TEntity : IEntity?
Posted
by DanM
on Stack Overflow
See other posts from Stack Overflow
or by DanM
Published on 2010-05-12T19:06:30Z
Indexed on
2010/05/12
19:54 UTC
Read the original article
Hit count: 512
I'm trying to use DbLinq with a SQLite database, but I'm running into a problem when I try to cast an ITable
as a Queryable<TEntity>
.
There is a known bug in DbLinq (Issue 211), which might be the source of my problem, but I wanted to make sure my code is sound and, if it is, find out if there might be something I can do to work around the bug.
Here is the generic repository method that attempts to do the cast:
public IQueryable<TEntity> GetAll()
{
return Table.Cast<TEntity>(); // Table is an ITable
}
This compiles, but if I pass in the interface IPerson
for TEntity
and the type of the entities in the table is Person
(where Person : IPerson
), I'm getting this error from DbLinq:
S0133: Implement QueryMethod Queryable.Cast.
Why am I trying to do this?
I have a library project that doesn't know the type of the entity until runtime, but it does know the interface for the entity. So, I'm trying to cast to the interface type so that my library project can consume the data.
Questions:
- Am I attempting an impossible cast or is this definitely a bug in DbLinq?
- How else could I go about solving my problem?
© Stack Overflow or respective owner