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)???????
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
[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:
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
Topolov
Member
680 Points
411 Posts
About LinqExpressionHelper
Feb 21, 2012 04:33 AM|LINK
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)???????
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: About LinqExpressionHelper
Feb 21, 2012 09:43 AM|LINK
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.
Always seeking an elegant solution.
Topolov
Member
680 Points
411 Posts
Re: About LinqExpressionHelper
Feb 21, 2012 08:46 PM|LINK
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
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: About LinqExpressionHelper
Feb 21, 2012 09:34 PM|LINK
Sorry Topolov, I've had it working to six level with no modifications.
Always seeking an elegant solution.
Topolov
Member
680 Points
411 Posts
Re: About LinqExpressionHelper
Feb 22, 2012 12:38 AM|LINK
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
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: About LinqExpressionHelper
Feb 22, 2012 08:08 AM|LINK
In the latest version you specify the next level on the upper level not on the lower level.
Always seeking an elegant solution.
Topolov
Member
680 Points
411 Posts
Re: About LinqExpressionHelper
Feb 24, 2012 12:50 AM|LINK
Sorry my IQ under 100: didn't get your answer
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: About LinqExpressionHelper
Feb 24, 2012 10:33 AM|LINK
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
Always seeking an elegant solution.
Topolov
Member
680 Points
411 Posts
Re: About LinqExpressionHelper
Feb 24, 2012 02:18 PM|LINK
thks a lot
Topolov
Member
680 Points
411 Posts
Re: About LinqExpressionHelper
Feb 24, 2012 03:02 PM|LINK
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?