LinqDatasource Where Clause on Field belong to a Linked Table via Foreign Key
I have 2 Tables, Emails and Owners that are linked with a foreign key . Emails has a Column Owner_FID which is a FK to Owner_ID of Owners.
I have a Linq Datasource for the Emails Table and i want to filter it using Where On the Owner.Owner_Name
Linq Datasource :
<asp:LinqDataSource ID="LinqEmails" runat="server" ContextTypeName="ACGlobalEmail.GlobalEmailDLDataContext" EntityTypeName="" TableName="Emails" EnableUpdate="False" Where="Name != null"
Select="new(Emall_Address,
Owner_FID,Contact_Name,Language,Owner.Owner_Name as Name)">
</asp:LinqDataSource>
i Have Followed MSDN Guidelines here http://msdn.microsoft.com/en-us/library/bb470363.aspx.. it seems 开发者_开发问答preety simple but i get this instead
Server Error in '/' Application.
No property or field 'Name' exists in type 'Email' Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.Query.Dynamic.ParseException: No property or field 'Name' exists in type 'Email'
The aliasing done by As
happens after the filtering done by Where
. Try changing your Where
to Owner.Owner_Name != null
(I haven't tried this), or perhaps you don't need the Owner.
精彩评论