English 中文(简体)
准则给实体:主要关键问题的问询所需工作
原标题:LINQ to Entities: Workaround needed for query on primary key

在银灯向实体使用LINQ的同时,在表格的主要关键点上产生疑问:

var query = (from b in PHOTOS
where b.RECORDID == selectedRecordId
select b);

参看<代码>http:// localhost/Dataservice.svc/PHOTOS(123456 )。 直到有人需要使用旧的亚洲开发银行(石化)来实施同样的法典时,科索沃才会如此。 结果是一份记录被退回,随后出现一个错误:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <code></code>
  <message xml:lang="en-US">An error occurred while processing this request.</message>
  <innererror>
    <message>A single resource was expected for the result, but multiple resources were found.</message>
    <type>System.InvalidOperationException</type>
    <stacktrace>   at System.Data.Services.Serializers.Serializer.WriteRequest(IEnumerator queryResults, Boolean hasMoved)&#xD;
   at System.Data.Services.ResponseBodyWriter.Write(Stream stream)</stacktrace>
  </innererror>
</error>

如果我用手法将问题重提:<条码>http:// localhost/Dataservice.svc/PHOTOS()? 页: 1 我怎么能写准则,以便迫使其使用过滤器而不是在母体中使用PK? 这一表格的所有结果都很有必要,因此,只是打败了第一个赢得的 t。

问题回答

Try:

var query = (from b in PHOTOS
             where b.RECORDID == selectedRecordId
             select b).FirstOrDefault;

这将造成一种单一结果(或目标违约,如果与该国际发展法没有记录,则通常不发生任何情况)。

Edit:

第二次尝试根据以下评论找到解决办法,在我前面没有民主选举学会的情况下,我可以核实:

var query = (from b in PHOTOS
             select b).Where(p => p.RECORDID == selectedRecordId);

My reasoning is that moving the where clause outside the initial query may force it to be a filter.

如果做不到这一点,我唯一的其他想法是考虑修改欧洲论坛,以压倒菲律宾群岛,迫使它没有主要钥匙。





相关问题
LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with ...

How can i write Linq2Entities Query with inner joins

How can I get data from these related entities. I want to get these columns only: Term.Name , related Concept_Term.Weight, related Concept.Id I wrote the SQL but I don t want to use select t....

Linq to enties, insert foreign keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any ...

Linq to entity timing problem

I created a data model that has some views from my database as entities,when I create a linq statment that has part of this view s entities ,the time processor take to execute the linq statment is ...

热门标签