0

我有一个由ProjectsOverallto组成的关系ProjectsProjectOverall包含 manyProjects并且 aProject被完全分配给 one ProjectOverall
一个有详细视图的ProjectOverall我想显示它的全部Projects。这在我的中留下了 2 个选项WebControlling.xsd

  1. 配置ProjectsOverall适配器以查找所有Projects引用它的 ID。
  2. 配置Project适配器以查找具有给定ProjectOverallID.

我尝试了这两种方法并偶然发现了以下问题之一:
选项 1,配置ProjectOverall
当返回行时,数据包含多个主键ID实例ProjectOverall。这会导致错误:

无法启用约束。一行或多行包含违反非空、唯一或外键约束的值

参考:如何解决常见错误强制 DataSet 不强制约束
这两个选项都不起作用。

[System.ComponentModel.DataObjectMethodAttribute
(System.ComponentModel.DataObjectMethodType.Select, false)]
public WebControlling.ProjectsDataTable GetAllProjectsForID(Guid ProjectOverallID)
{
    WebControlling.ProjectsDataTable projects = new WebControlling.ProjectsDataTable();
    try
    {
        projects.Merge(Adapter.GetAllProjectsForID(ProjectOverallID));
    }
    catch (Exception e)
    {
        throw e;
    }
    return projects;
}

sql(总过分杀伤力,但只返回一个条目时有效):

SELECT   wc_Countries.Name AS CountryName, wc_OrganisationUnit.Name AS OEName, wc_Projects.ID AS ProjectID, wc_ProjectsOverall.ID AS ProjectOverallID, wc_Projects.Name AS ProjectName, 
                         wc_ProjectsOverall.ProjectName AS ProjectOverallName, wc_ProjectsOverall.*, wc_Countries.*, wc_OrganisationUnit.*, wc_Projects.*
FROM         wc_ProjectsOverall INNER JOIN
                         wc_Countries ON wc_ProjectsOverall.CountryID = wc_Countries.ID INNER JOIN
                         wc_OrganisationUnit ON wc_ProjectsOverall.OrganisationUnitID = wc_OrganisationUnit.ID INNER JOIN
                         wc_Projects ON wc_ProjectsOverall.ID = wc_Projects.ProjectOverallID AND wc_Countries.ID = wc_Projects.CountryID AND 
                         wc_OrganisationUnit.ID = wc_Projects.OrganisationUnitID
WHERE     (wc_ProjectsOverall.ID = @ProjectOverallID)

在详细视图中:

<%-- Sub Project Data Source --%>
<asp:ObjectDataSource ID="ObjectDataSourceProjects" runat="server" 
                          OldValuesParameterFormatString="{0}" 
                          SelectMethod="GetAllProjectsForID" 
                          TypeName="ProjectsOverall" 
                          DataObjectTypeName="System.Guid">
    <SelectParameters>
        <asp:QueryStringParameter QueryStringField="ID" Name="ProjectOverallID" Type="Object" /> 
    </SelectParameters>
</asp:ObjectDataSource>

第二个选项不起作用,因为当我将类型切换为时,DataSourceTypeName="Projects不知道如何访问视图中存在的 ID。
该视图显示 a 的所有属性,ProjectOverall并且应该显示它的所有sProjects`。

<ContentTemplate>                   
                    <%-- Displays all Sub-Projects  --%>
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                            <asp:GridView ID="GridViewProjects" runat="server" AllowPaging="True" AllowSorting="True"
                                AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="ObjectDataSourceProjects" PageSize="5">
                                <Columns>
                                    No need to show all    
                                </Columns>
                                <EmptyDataTemplate>
                                    No project matched your filter criteria. <br />
                                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="<%# Request.RawUrl %>">Return to the project overview.</asp:HyperLink>
                                </EmptyDataTemplate>
                            </asp:GridView>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </ContentTemplate>

有没有一个干净的解决方案来做这些事情?

4

0 回答 0