Dynamic Data Entity - data filter according to the connected user RRS feed

  • Question

  • User-711950860 posted

     I am new to dynamic data technology and in my first webapp i would like to apply a filter to records shown to users.

    My DB Schema:
    Utente (1) ------> (*) Appezzamento (1) ------> (*) Raccolta

    Every "Utente" (User) has one or more "Appezzamento"; every "Appezzamento" has one or more "Raccolta".
    In \Raccolta\ListDetails.aspx i would like to filter only the "Raccolta" records according to the connected user (Utente).
    I suppose the best position to code this filter is on the "OnSelecting event handler" of the EntityDataSource because data aren't loaded yet.
    In my attempt i use Where property of GridDataSource and also WhereParameters without results.
    Any suggestions?

    Thanks in advance
    Wednesday, November 26, 2008 7:09 AM

All replies

  • User-330204900 posted

    Hi , have a look at these articles from my blog:

    1. DynamicData - Limit the Filter Fields
    2. DynamicData - Automatic Column Update

    Article 3. is an update to article 2 which only covered Linq to SQL.

    Hope this helps [:D]

    Wednesday, November 26, 2008 8:50 AM
  • User-711950860 posted

    Thank you for replay to my request

    To solve my problem, I thought of something similar to


    cso_Entities cso = new cso_Entities();
    string filter = string.Empty;
    //ID of the connected user
    int appoId = 0;
    int.TryParse(User.Identity.Name.ToString(), out appoId);  
    //Appezzamento of the connected user
    var appezzamentos = from app in cso.Appezzamento.Include("Produttore").ToList()
                        where app.Produttore.UTE_Id == appoId
                        select app.APP_Id;
    //create the filter
    foreach (var app in appezzamentos)
        filter += " || it.Appezzamento.APP_Id == " + app.ToString();
    filter = filter.Substring(3); 
    //apply the filter
    GridDataSource.AutoGenerateWhereClause = false;
    GridDataSource.Where = filter;


    This solution generate one error that refer to other entity in association with Appezzamento.

    This is an example of the error:

    << Name of the parameter 'AnagraficaFasiFenologiche.AFF_Id' specified is invalid. The names of parameter must begin with a letter and can contain only letters, numbers and underscores. >>
    I think that this happens because the parameters of the WhereParameters collection are not inserted


    Thursday, November 27, 2008 4:54 AM
  • User-330204900 posted

    Hi I pasted the one wrong article previously try this:

    DynamicData - Limit Data Displayed By User

    I'm not sure that you need the:

    GridDataSource.AutoGenerateWhereClause = false;

    As this will stop the filters on the page working.

    Hope this helps [:D]

    Thursday, November 27, 2008 6:46 AM