Matt Dargavel
unread,Aug 27, 2009, 5:52:02 AM8/27/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to DbLinq
Hi there,
I have a couple of tables that have a few fields that are the same
and I do some common operations on both the tables. To try and
minimise code duplication I created an interface that declared these
common fields and applied the interface to both table classes.
This let me create a Generic function that did the query I wanted to
do. As a simplified example:
private static IEnumerable<T> PrefixMatch<T>(this IQueryable<T> query,
string searchValue) where T : IRoutingGroupLookup
{
var lookups = query.Where(l => (l.LookupType ==
RoutingLookupType.Prefix)).OrderByDescending(l =>
l.LookupValue.Length);
return lookups;
}
And the code to use it:
MyDb db = new MyDb(conn);
db.InboundRoutingGroupLookups.PrefixMatch(myPrefix).FirstOrDefault();
db.OutboundRoutingGroupLookups.PrefixMatch(myPrefix).FirstOrDefault();
When trying to run the query, DBLinq throws an ArgumentException in
SqlProvider.GetLiteral(...). The operation type it's trying to do is
a MemberAccess in the where clause. If I replace the generic function
with two identical functions that use the actual table classes then it
all works ok. I tried looking through the source code but couldn't
work out where the Expression creation wasn't recognising the member
as a table column.
Is it possible to do this kind of thing? If so, if anyone could
give me some pointers on where I should look they'd be gratefully
received!
Best Regards,
Matt.