필자의 제목에서 일부 엔티티 SQL 요청을 시도하는 데 문제가 있습니다.오류는 표현식이 CollectionType이어야한다고 말합니다.
전체 코드는 검색 엔진으로 사용해야합니다. 문자열을 만든 다음 쿼리로 변환해야합니다. 나는 linq-to-SQL을 사용하여 모든 것을 이미 수행했다. 그러나 문자열을 linq 쿼리로 변환하는 것은 불가능합니다. 그러나, 나는 stackoverflow에서 일종의 솔루션을 발견했지만 결코 사용할 수 없었습니다 : String.ToLinqQuery(). 그것은 Visual Studio에서 알려지지 않았기 때문에 이에 대한 문서를 찾을 수 없습니다. 여기에 내 모든 코드
The specified expression must be of CollectionType. Near parenthesized expression, line 1, column 20.
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.Data.EntitySqlException: The specified expression must be of CollectionType. Near parenthesized expression, line 1, column 20.
Source Error:
Line 145: Meetings
Line 146:
Line 147: @For Each meeting In Model.Meetings
Line 148: @@meeting.date
Line 149: @Html.ActionLink("Edit", "Edit", "Meeting", New With {.id = meeting.idmeeting}, "Null")
그리고 : 컨트롤러 :
Imports System.Data.Objects
Imports System.Linq.Expressions
Namespace MvcApplication4
Public Class SearchController
Inherits System.Web.Mvc.Controller
<HttpPost()>
Function Index(search As String, choix As Integer) As ActionResult
Dim test As Integer = Request("choix")
Dim chaine As String = Request("searchString")
Dim message As String = "message"
Dim requete As String = "Select value p FROM('db.meeting') as p where p.compteRendu LIKE '%chaine%'"
Dim meetings = New ObjectQuery(Of meeting)(requete, db)
Dim model = New SearchModel With {
.Meetings = meetings,
}
Return View(model)
End Function
End Class
End Namespace
모델 :
Public Class SearchModel
Public Property Meetings As IEnumerable(Of meeting)
End Class
보기 :
@Modeltype MvcApplication4.SearchModel
@<fieldset>
<legend>Meetings</legend>
@For Each meeting In Model.Meetings
@<ul> @meeting.date
@Html.ActionLink("Edit", "Edit", "Meeting", New With {.id = meeting.idmeeting}, "Null") </ul>
@<li> @Html.Raw(meeting.compteRendu.Replace(System.Environment.NewLine, "<br />"))</li>
Next meeting
</fieldset>
있지만, 여기에 오류가 내가 얻을입니다
내가 뭘 잘못하고 있니? 여기
는 ESQL 쿼리 부분에서 내 .edmx 모델<EntityType Name="meeting">
<Key>
<PropertyRef Name="idmeeting" />
</Key>
<Property Name="idmeeting" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
<Property Name="FK_meet_client" Type="int" />
<Property Name="FK_meet_contact" Type="int" />
<Property Name="FK_meet_opport" Type="int" />
<Property Name="FK_meet_user" Type="int" />
<Property Name="compteRendu" Type="longtext" />
<Property Name="date" Type="datetime" />
<Property Name="adresse" Type="text" />
</EntityType>
아무런 변화가 없습니다. 나는 컬렉션을 얻지 못했기 때문에 그런 것 같지만, 어떻게해야할지 모르겠다. ... –
아마도 db.meeting은 모델에 설정된 엔티티의 유효한 이름이 아닐 수도있다. –
Linq를 사용했을 때 쿼리가 잘 작동했습니다. 좀 더 역동적 인 것이 필요했기 때문에 나는 바꿨다. 나는이 문제가 "ObjectQuery"의 매개 변수 안에 있다고 생각한다. –