473,414 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Lambda expression in dlinq attribute

I need to use lambda expressions or other way to
specify default query for dlinq entity type.
Code below causes compile error shown in comment.
How to fix ?
Maybe to use [QueryAttribute( "Supplier", "d=>
d.Discriminator==""Domestics"" ")] ?

Andrus.

using System;
using System.Linq;

// '<' unexpected : attributes cannot be generic
[QueryAttribute<Supplier>(d=d.Discriminator=="Domes tics")]
class DomesticsSupplier {
public string Discriminator { get; set; };
public string Name { get; set; };
}

class QueryAttribute<TEntity: Attribute {
IQueryable<TEntityQuery;
internal QueryAttribute(IQueryable<TEntityquery) {
Query = query;
}
}

Jun 27 '08 #1
5 2091
Well, the compiler message is clear enough; you would have to pass a
Type through, not a generic. Also, your lambda isn't an IQueryable<T>
- it is a Func<T, boolor an Expression<Func<T, bool>- but I doubt
you could use iether directly in an attribute.

I would suggest something like
[QueryAttrubute(Condition="SupplierDiscriminator",
Type=typeof(Supplier)]
....
public static Expression<Func<Supplier, bool>SupplierDiscriminator {
get {return d=d.Discriminator=="Domestics";}
}

(I would make Type optional, defaulting to the current)

Note that this usage is very different (as I understand it) to how
NHibernate uses QueryAttribute, and you'll need to code it up by
hand...

Marc
Jun 27 '08 #2
Additional; my unserstanding is that EF supports much better
inheritance than LINQ-to-SQL; a taster is here:
http://blogs.msdn.com/adonet/archive...framework.aspx

Marc
Jun 27 '08 #3
Actually, it looks like LINQ to SQL supports
InheritanceMappingAttribute, and IsDiscriminator on ColumnAttribute.
Jun 27 '08 #5
Well, since .NET has single inheritance, you can't have two dimensions
of discriminator... could you perhaps simply map the two columns into
a single discriminator column? This sound like something EF could
handle (perhaps), or maybe a UDF when reading... but to be honest I
think two discriminators is making life hard...
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: George Yoshida | last post by:
Just out of curiosity, is there any way to get the name of a lambda expression? Lambdas are anonymous functions, so it's a stupid idea to get the name of it. But if it's possible, how could I? ...
63
by: Stephen Thorne | last post by:
Hi guys, I'm a little worried about the expected disappearance of lambda in python3000. I've had my brain badly broken by functional programming in the past, and I would hate to see things...
26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
6
by: Xavier Décoret | last post by:
Hi, I cannot find the way to do generic lambda functions using the lambda syntax in python. I am probably missing a point. For example, the code # f = lambda : print "hello" # f()
23
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
5
by: Octal | last post by:
How does the lambda library actually works. How does it know how to evaluate _1, how does it recognize _1 as a placeholder, how does it then calculate _1+_2, or _1+2 etc. The source files seem a...
11
by: ssecorp | last post by:
I am never redefining the or reassigning the list when using validate but since it spits the modified list back out that somehow means that the modified list is part of the environment and not the...
4
by: CSharper | last post by:
I have following XML <root> <Person id="1"> <Name>a</Name> </Person> <Person id="2"> <Name>b</Name> </Person> </root>
11
by: puzzlecracker | last post by:
I am not understanding what's happening in the code below (from accelerated c#) -- I know what the outcome but not how .net does it: using System; using System.Linq; public class LambdaTest...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.