Last post Aug 19, 2010 10:44 AM by pallone
Aug 19, 2010 07:38 AM|pallone|LINK
I am just starting with dynamic data. I have an enttity framework called UsersModel.edmx.
It returns a list of all companies in the tblCompany table. This list is really big.
I need to filter the list returned to all user controls on the client so that it only returns the company that have a CompanyTypeId= 2 or CompanyTypeId= 3 and company name != "".
1 - Is it possible to filter the company list returned on the server so that I can filter only once for all the controls that use that on the client?
My ideas was to do something like this using linq and lambda but I am not sure how:
return tblCompanys.Where(c => c.CompanyTypeId == 2 || c.CompanyTypeId == 3 && ).Where(c=>c.CompanyName != "").OrderBy(c => c.CompanyName).Distinct().OrderBy(c=>c.CompanyName);
2 - I have created a partial class and a metadata class and added the DisplayColumn attribute to use the company name and sort by company name ascending.
Could I use the code to filter the returned companies in this? where?
public partial class tblCompany
public class tblCompanyMetadata
This is the code generated by the EF:
public ObjectSet<tblCompany> tblCompanies
if ((_tblCompanies == null))
_tblCompanies = base.CreateObjectSet<tblCompany>("tblCompanies");
private ObjectSet<tblCompany> _tblCompanies;
Aug 19, 2010 09:02 AM|klca|LINK
My guess is that you can filter accordingly by using a proper "where" clause inside the
Carlos Porras (El Salvador)
Aug 19, 2010 09:26 AM|pallone|LINK
Thanks for your reply.
Are you talking about the EntityDataSource in the List.aspx page?
I had a look the the code but I am not sure how I am going to do it. Could you please provide some light based on the code I copied below?
Also, wouldn't it be better to limit the companies returned in the EF? Is it possible to it in the EF?
Aug 19, 2010 09:37 AM|pallone|LINK
I forgot to paste the code:
<asp:QueryableFilterRepeater runat="server" ID="FilterRepeater">
<asp:Label runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" />
<asp:DynamicFilter runat="server" ID="DynamicFilter" OnFilterChanged="DynamicFilter_FilterChanged" /><br />
<asp:EntityDataSource ID="GridDataSource" runat="server" EnableDelete="true" />
<asp:QueryExtender TargetControlID="GridDataSource" ID="GridQueryExtender" runat="server">
<asp:DynamicFilterExpression ControlID="FilterRepeater" />
Aug 19, 2010 09:38 AM|klca|LINK
I understand that you would like to filter everything at once in a single place so if you were to use something like this in you control it will solve your problem. I am assuming you are working with VS2010. Obviously that I rather prefer simple solutions
than complex ones when it comes to solve problems and I know that there must be a way of doing all of this at code level but it seems so simple and clear this way than I will go to see if it works and if it does I will move on ... that's my thinking
Where="it.PlayerID == @playerid">
Aug 19, 2010 09:42 AM|pallone|LINK
But how do I say I want to filter only for the tblCompanies entity.
I have other entities in my EF like tblUsers, tblLocation, etc.. and I need a way to specify the filter only for the tblCompanies entity.
Aug 19, 2010 09:46 AM|klca|LINK
Make a copy of your pages under a folder whose name should be identical to the table as it is named in the model and make the changes there. The change wil work for that table only. The folder MUST be placed under the CustomPages Folder
P.S. There is an Scott Hanselmann's video about URL routing on the ASP.Net Official web site which clearly explains all of this
Aug 19, 2010 10:44 AM|pallone|LINK
Thanks. I will have a go.