本文介绍了如何使用多对多表为用户显示正确的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在创建一个应用程序,其中用户必须提交一个几乎正常工作的表单,但我目前正在尝试做的是显示与该应用程序匹配的每个用户的所有应用程序项目。 userID 1可以看到应用程序1-4,但不能看到5-8,我显示了用户可以看到的每个应用程序的内容,因此如何以逻辑方式显示该应用程序以获取正确的信息,表格看起来像这样ClientTable clientID clientName 1 galway 2 Donegal ApplicationclientTable ClientID ApplicationID 1 1 1 2 2 3 3 4 ApplicationTable ApplicationID ApplicationName 1 Avail1 2 Avail2 3 Roster1 4 Roster2 ' 在控制器中 Dim userModel = 新 IssueTracker.ClientUserProjectIssue() userModel.cTable = dbServer.ClientTables.Where( Function (x)x.userID = getuserID)。ToList() userModel.proTable = dbServer.ApplicationTypeTable.Where( Function (x)x.ApplicationID = ApplicationID( in many to 许多表))。ToList() 返回查看(userModel) ' 在视图中 ' 这里我想显示每个所选ID的下拉列表 @For 每个 ApplicationID 在 Model.cTable @ Html.DropDownList( ApplicationID, Nothing , String .Empty,新 使用 {Key。[ class ] = form-control,Key .required = required}) 下一页 我正在努力的部分是它背后的逻辑解决方案 听起来你需要加入表格。这样的事情: DECALRE @ClientId INT SET @ClientId = 1 SELECT at at。 ApplicationId,at.ApplicationName 来自ApplicationTable at JOIN ApplicationclientTable act ON act.ApplicationId = a.ApplicationId JOIN ClientTable ct ON ct.ClientId = act.ClientId WHERE ClientId = @客户端Id I am creating an application in which a user has to submit a form which is nearly working but what I am currently trying to do is display all the application items for each user that is matched with that application.userID 1 can see application 1-4, but not 5-8, I what to display every application that user can see, so how can I logically display that to get the correct information, tables look like this ClientTable clientID clientName 1 galway 2 DonegalApplicationclientTableClientID ApplicationID 1 1 1 2 2 3 3 4ApplicationTableApplicationID ApplicationName 1 Avail1 2 Avail2 3 Roster1 4 Roster2'In the controllerDim userModel = New IssueTracker.ClientUserProjectIssue()userModel.cTable = dbServer.ClientTables.Where(Function(x) x.userID = getuserID).ToList()userModel.proTable = dbServer.ApplicationTypeTable.Where(Function(x) x.ApplicationID= ApplicationID(in many to many table)).ToList()Return View(userModel)'In the view'Here I want to display a dropdownlist for each chosen ID@For Each ApplicationID In [email protected]("ApplicationID" , Nothing, String.Empty, New With {Key .[class] = "form-control", Key .required = "required"})NextThe part I am struggling with is the logic behind it 解决方案 Sounds like you need to join the tables. Something like this:DECALRE @ClientId INTSET @ClientId = 1SELECT at.ApplicationId, at.ApplicationNameFROM ApplicationTable atJOIN ApplicationclientTable act ON act.ApplicationId = a.ApplicationIdJOIN ClientTable ct ON ct.ClientId = act.ClientIdWHERE ClientId = @ClientId 这篇关于如何使用多对多表为用户显示正确的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-26 20:51