c# - Using custom attributes in a SearchFilters object to contain the target field to be searched -
big picture
i maintain large web application primary function of managing orders. mvc on c# application using ef6 data. there lots of search screens. right every search coded without code re-use (before time, swear!).
what i'm trying do
i'm building inheritable search object that, given search, can build derived class lists search fields , uses attributes specify:
- the display name of field
- the comparison type done (= != > < <= >=)
- the field of target object searched
the base class uses information put query.
my struggle
the last attribute 1 i'm having trouble with. how can use attribute specify target field of object searched? constraints:
- if @ possible don't want use string here. i'd reference field if rename field doesn't break searches.
- the target field need able target sub-objects well. example, ordernumber search field needs target order.id, name search field needs target order.customer.name.
- the target cannot field of specific instance of object field being used generate linq query.
here's example of derived search class can see looks like. in advance guidance can offer. please note "linkedfield" attributes have been added illustrate there. doesn't work, of course. :)
//derived class contains search fields public class orderfilterset: searchtools.filterset { [linkedfield(/*??*/)] //should contain link target field [comparison(expressiontype.equal)] [display(name = "order number")] public string id { get; set; } [linkedfield(order.status)] [comparison(expressiontype.equal)] [display(name = "current status")] public string status { get; set; } [linkedfield(order.createddt] [comparison(expressiontype.lessthanorequal)] [display(name = "set on or before")] public datetime createddateend { get; set; } [linkedfield(order.createddt] [comparison(expressiontype.greaterthanorequal)] [display(name = "set on or after")] public datetime createddatestart { get; set; } [linkedfield(order.customer.name] //note target field sub-object [comparison(expressiontype.equal)] [display(name = "customer name")] public string name { get; set; } }
Comments
Post a Comment