i am getting a weird error. my sproc looks like this
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
notice the last like will select the newly inserted record
public static int Save(int id, string question, string answer, WorkflowStatus status, string modifiedBy)
{
using (var dc = ProjectLogic.Ge开发者_运维百科tDataContext())
{
return dc.SaveFaq(id, question, answer, status.ToString(), modifiedBy).Single().Id;
}
}
i get an error like this..
'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?)
Indeed wrong namespace.
One namespace is regular Linq, the other one is Linq2sql.
http://msdn.microsoft.com/en-us/library/gg145045.aspx
apperently i'm using the wrong namespace
use this
using System.Linq;
NOT this
using System.Data.Linq;
I have no idea why...
精彩评论