Using Dynamic Queries

Posts   
 
    
Posts: 23
Joined: 19-Aug-2008
# Posted on: 18-Sep-2008 01:09:19   

Hi,

I have an event handler that takes the text a user enters and tries to find all records where one of the fields starts with the text. From everything I read this should work.


    protected void btnSearch_Click(object sender, ImageClickEventArgs e)
    {
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            LinqMetaData metaData = new LinqMetaData(adapter);

            var materialEntities = from m in metaData.Material
                                   join mp in metaData.MaterialProperties on m.MaterialId equals mp.MaterialId
                                   join sp in metaData.StoragePlan on mp.MaterialId equals sp.MaterialId
                                   orderby m.MaterialNm ascending
                                   select new
                                   {
                                       sp.StorageCriteriaSeqId, //TODO: change to smart code
                                       m.MaterialId,
                                       m.MaterialNm,
                                       sp.PlanNm,
                                       mp.MaterialSubType.MaterialSubTypeDesc,
                                       mp.AhopsGrpCd,
                                       mp.HazardsClassCd,
                                       sp.StorageCriteria.StorageDuration,
                                       sp.PlanApprovalDt

                                   };
            if (txtSearch.Text.Length > 0)
                grdMain.DataSource = materialEntities.Where(me => me.MaterialNm.StartsWith(txtSearch.Text, StringComparison.OrdinalIgnoreCase));
            else
                grdMain.DataSource = materialEntities;

            grdMain.DataBind();
        }
    }

Any suggestions?

Thanks, Mike

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Sep-2008 06:36:36   

As far as I can see, your code should work nice. Are you experimenting troubles?

David Elizondo | LLBLGen Support Team