locked
About LinqExpressionHelper RRS feed

  • Question

  • User1043796333 posted

    The LinqExpressionHelper class goes more or less like this:

       public static class LinqExpressionHelper
        {
            internal static IQueryable GetQueryFilteredByParent(this IQueryable sourceQuery, 
                MetaForeignKeyColumn fkColumn, String fkSelectedValue)
    
            internal static IQueryable GetQueryFilteredByParent1(this IQueryable sourceQuery,
        MetaForeignKeyColumn fkColumn, String fkSelectedValue, MetaForeignKeyColumn pk1)
    
            internal static Expression BuildWhereClause(MetaForeignKeyColumn fkColumn, 
                ParameterExpression parameterExpression, string fkSelectedValue)
    
            public static MethodCallExpression BuildSingleItemQuery(IQueryable query, 
                MetaTable metaTable, string[] primaryKeyValues)
    
            public static MethodCallExpression BuildItemsQuery(IQueryable query, 
                MetaTable metaTable, IList<MetaColumn> columns, string[] values)
    
            public static MethodCallExpression BuildWhereQuery(IQueryable query, MetaTable metaTable, 
                MetaColumn column, string value)
    
            public static MethodCallExpression BuildCustomQuery(IQueryable query, 
                MetaTable metaTable, MetaColumn column, string value, QueryType queryType)
    
            public static BinaryExpression BuildWhereBody(ParameterExpression parameter, 
                IList<MetaColumn> columns, string[] values)
    
            private static BinaryExpression BuildWhereBodyFragment(ParameterExpression parameter, 
                MetaColumn column, string value)
    
            private static object ChangeValueType(MetaColumn column, string value)
    
            public static Expression GetValue(Expression exp)
    
            private static Type RemoveNullableFromType(Type type)
    
            public static Type GetUnderlyingType(Type type)
    
            public static Expression Join(IEnumerable<Expression> expressions, 
                Func<Expression, Expression, Expression> joinFunction)
    
            public static Expression CreatePropertyExpression(Expression parameterExpression, string propertyName)
    
            private static bool TypeAllowsNull(Type type)
    
            internal static object ChangeType(object value, Type type)

    It seems that this methods are required if you are going to build Linq sentences on the fly passing a parameter BUT I ask this:

    If I have a cascading of 5 or more levels carried on by PKs which I have already added to my Metedata file (I have added more Cascade ditectives in my  base class, up to seven levels)

    How can I rewrite all this methods in order to achieve proper cascading from level 3 on (I have obviously added the logig for the firts 2, which was a little easier)???????

    Tuesday, February 21, 2012 12:33 AM

Answers

  • User-330204900 posted

    Hi Topolov, here's how my cascade works

    [MetadataType(typeof(VehiclesMetadata))]
    public partial class Vehicles
    {
        public partial class VehiclesMetadata
        {
            //... other field removed for brevity
    
            public object Manufacturer { get; set; }
    
            [Cascade("Manufacturer")]
            public object VehicleType { get; set; }
    
            [Cascade("VehicleType")]
            public object Model { get; set; }
    
            [Cascade("Model")]
            public object Style { get; set; }
    
            [Cascade("Style")]
            public object EngineType { get; set; }
        }
    }

    As you can see here each navigation property points to the level above where you have the structure:

    Manufacturer->VehicleType->Model->Style->EngineType

    this could be a selection like this:

    Ford->Van->Transit->HighLoader->Diesel

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 24, 2012 6:33 AM

All replies

  • User-330204900 posted

    Sorry Topolov, I thin it shoudl work with any number of levels in the cascade, that is why its Linq Expressions to so they are generic.

    Tuesday, February 21, 2012 5:43 AM
  • User1043796333 posted

    Naughton: for this to work you'll need to have a way of adding additioanl "Cascade" levels in you MetaData file so I have added as many as 7 iof them

    Having said that: my question goes this way ...

    How can you modify the LinqExpressionHelper methods so they can accept as arguments as many as 7 levels (any number between 1 and 7)?

    That's not a generic thing but something which must be customized

    LinqExpressionHelper is designed to work with 1 level only, isn't it?

    By the way: I have made all required changes as to make all other 6 levels to be properly defined: Cascade2, Cascade3, Cascade4, Cascade5, Cascade6 and Cascade7

    Tuesday, February 21, 2012 4:46 PM
  • User-330204900 posted

    Sorry Topolov, I've had it working to six level with no modifications.

    Tuesday, February 21, 2012 5:34 PM
  • User1043796333 posted

    I'd like to understand how do you define such levels in your MetaData file

    There is only ONE Cascade attribute thgat you can use, sin't it" How do you define the rest of the levels?

    Moreover, I can have different levels of dependency for each one of my dropdownlists so I need to know how you do that

    please, I don't get it

    Maybe with a sample of your MetaData file will do it

    Tuesday, February 21, 2012 8:38 PM
  • User-330204900 posted

    In the latest version you specify the next level on the upper level not on the lower level.

    Wednesday, February 22, 2012 4:08 AM
  • User1043796333 posted

    Sorry my IQ under 100: didn't get your answer

    Thursday, February 23, 2012 8:50 PM
  • User-330204900 posted

    Hi Topolov, here's how my cascade works

    [MetadataType(typeof(VehiclesMetadata))]
    public partial class Vehicles
    {
        public partial class VehiclesMetadata
        {
            //... other field removed for brevity
    
            public object Manufacturer { get; set; }
    
            [Cascade("Manufacturer")]
            public object VehicleType { get; set; }
    
            [Cascade("VehicleType")]
            public object Model { get; set; }
    
            [Cascade("Model")]
            public object Style { get; set; }
    
            [Cascade("Style")]
            public object EngineType { get; set; }
        }
    }

    As you can see here each navigation property points to the level above where you have the structure:

    Manufacturer->VehicleType->Model->Style->EngineType

    this could be a selection like this:

    Ford->Van->Transit->HighLoader->Diesel

    Hope this helps

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 24, 2012 6:33 AM
  • User1043796333 posted

    thks a lot

    Friday, February 24, 2012 10:18 AM
  • User1043796333 posted

    Your answer is ok Naughton; NEVERTHELESS (and this is something that might be something wrong from my part on which comes to the database model) I have some entities whose dependency is not that linear 

    I have for instance an entity "Transactions" which collects information all transactions performed in the system, let's say: sales to customers, buys from suppliers, inventory stock transactions like: physical counting, adjustments for damages, loses, etc. Also registration of orders in process (merchandise on the route which is supposed to be delivered by the supplier at an specific date). 

    That entity has a lot of incoming Foreign Keys which have some kind of dependency from the same parent entities

    For instance: customers and suppliers both have dependency on the "type of business (from my side not5 theirs)" "business scope (something required by the Ministry of Treasury)", "store who's buying/selling", "person who's buying/selling (from login routines)", "some accounting catalog's dependency, etc.

    SO THE PROBLEM IS HERE that you can't uses sometimes the last of the cascades in the MetaData file but some of the which is in the middle of a prior chain and ALSO that some of them (dependencies FKs) must be "repeated" as to create proper cascading for some of the other entities involved inb a transaction

    THIS IS BECAUSE the Cascading attribute works based on "positioning" inside the list but I rather need to have defined each one of the cascading chains in their own specific order

    THAT"S WHY I created additional properties: Cascading2, Cascading3, Cascading4, Cascading5, Cascading6 and Cascading7

    So I have 7 levels of cascading for any of my incoming FKs entities

    BUT THE PROBLEM IS THAT I MUST rewrite  LinqExpressionHelper so it sees and do filtering accordingly

    PROBLEM IS that all lamda expressions inside that class works only with one parameter for creating the "where" sentence

    Do you get my point?

    Friday, February 24, 2012 11:02 AM
  • User-330204900 posted

    I have some entities whose dependency is not that linear 
    My sample is designed to work in that way there must be a relationship in the DB and model for it to work :(

    Friday, February 24, 2012 11:29 AM
  • User1043796333 posted

    I'm trying to get a version of my own to do the filtering

    PROBLEM IS that I don't know how to take the result from previous query and refilter it again

    PROBLEM IS that this can be achieved in a non-very elegant fashioned way and it seems to me that rebuilding the query each time (passing parameters to teh old values) will reult in as many round trips to the database as filters I have to build a cascade FOR EACH ELEMENT TO BE "CASCADEd"

    So I'd like to know hor LINQ really works in order to do just one trip to the database and get all results at once top do the filtering (cascading)

    Friday, February 24, 2012 1:03 PM
  • User1799985857 posted

    What is this LInqHelper thing?

    Yules

    Friday, March 2, 2012 12:57 AM
  • User-330204900 posted

    Hi Yules, this for advanced techniques in DD i.e. handling queries to the DB when you don't know before hand what the table will be.

    Friday, March 2, 2012 7:16 AM