what I have are two tables, Publication and DTPersonnel. Publication has a primary Key and the other (DTPersonnel) has a field that is link back Publication. I sent up a DBML layout for my LinqDataSource and link the two tables.. I have added the LinqDataSource component to my web page and (for testing) a label.
I then set up the label data-binding to point to a field in DTPersonnel.DTRoleID like this:
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
DataSourceID="LinqDataSource1">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# BIND("DTPersonnels.DTRoleID") %>'></asp:Label>
</ItemTemplate>
</asp:FormView>
</asp:Content>
My LinqDataSource is setup like this:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Layout.aspx.cs" Inherits="AequorPubTracker.Account.Layout" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:LinqDataSource ID="LinqDataSource1" runat="server"
ContextTypeName="AequorPubTracker.LayoutDataContext" EntityTypeName=""
onselecting="LinqDataSource1_Selecting" TableName="Publications"
Select="new (DTPersonnels.DTRoleID,PublicationID, DTPersonnels, ActLAYDate, ActRRIPDate, ActPPIDate, ActPPODate, ActECTWDate, TargetECTWDate, TargetPPIDate, TargetRRIPDate, TargetPPODate, TargetLAYDate)">
</asp:LinqDataSource>
But when I run the app in the browser I get the following error:
Exception Details: System.Web.Query.Dynamic.ParseException: No property or field 'DTRoleID' exists in type 'EntitySet`1'
I hope I gave enough information any help would be great.
I assume since you are specifying the select clause, this is a read-only view of the data. If that is so, your problem has a fairly straightforward solution. However, if it is not so (of which I am uncertain since that your code calls the
Bind
method rather thanEval
), there is more complex handling required to update related fields as aLinqDataSource
with theSelect
member specified cannot allow updating.Ensure you select the
DTPersonnels
member in your clause, but removeDTPersonnels.DTRoleID
from the selection. If you callEval("DTPersonnels.DTRoleID")
it will display the related record's member value.I presume, however, there is also a problem in the configuration of your schema file. From what I can infer, you expect there to be a 1-to-1 relationship between
Publications
andDTPersonnel
. However, since the error indicates that there is no member onEntitySet
, that implies that you have allowed a 1-to-many relationship wherePublications
have manyDTPersonnel
. If there is not a 1-to-1 relationship, your code will not be able to determine which related record'sDTRoleID
to display.If you actually DO intend for there to be many
DTPersonnel
related to aPublication
, then you may want to approach this from the other way around of displaying a list ofDTPersonnel
and showing their relatedPublication
's data instead.