ISingleResult不包含'Single'的定义,也没有扩展方法'Single'

时间:2011-10-06 22:31:16

标签: linq-to-sql

我得到一个奇怪的错误。我的sproc看起来像这样

CREATE PROCEDURE [dbo].[SaveFaq] (  @Id int , @Question nvarchar(MAX) , @Answer nvarchar(MAX) , @Status nvarchar(50) , @ModifiedBy nvarchar(50)  )
AS 
    SET NOCOUNT ON ; 
    Declare @newId as INT  
    if not exists(select * from [Faq]  where [Id] = @Id)
    begin 
        INSERT into [Faq] (  [Question], [Answer], [Status], [ModifiedBy], [CreatedDate] ,  [CreatedBy] ,  [ModifiedDate] )  VALUES (   @Question, @Answer, @Status, @ModifiedBy, GETDATE() , @ModifiedBy ,  GETDATE() )
        select @newId = SCOPE_IDENTITY()
    end
    else begin  
        UPDATE [Faq] SET   [Question] = @Question, [Answer] = @Answer, [Status] = @Status, [ModifiedBy] = @ModifiedBy,  [ModifiedDate] = GETDATE()
        Where Id = @Id
        select @newId = @Id
    end   
    Select * from  [Faq] where Id = @newId

注意最后一样会选择新插入的记录

public static int Save(int id, string question, string answer, WorkflowStatus status, string modifiedBy)
    {
        using (var dc = ProjectLogic.GetDataContext())
        {
            return dc.SaveFaq(id, question, answer, status.ToString(), modifiedBy).Single().Id; 
        }
    }

我收到这样的错误..

'System.Data.Linq.ISingleResult<Web.Data.DataContext.SaveFaqResult>' does not contain a definition for 'Single' and no extension method 'Single' accepting a first argument of type 'System.Data.Linq.ISingleResult<Web.Data.DataContext.SaveFaqResult>' could be found (are you missing a using directive or an assembly reference?)

2 个答案:

答案 0 :(得分:3)

确实是错误的命名空间。

一个名称空间是常规Linq,另一个是Linq2sql。

http://msdn.microsoft.com/en-us/library/gg145045.aspx

答案 1 :(得分:0)

显然我正在使用错误的命名空间

使用此

using System.Linq; 

不是这个

using System.Data.Linq; 

我不知道为什么......