2
我有一個合併存儲過程。我將proc映射到插入和更新的實體。當我運行時,我得到以下錯誤 - 任何想法?指定合併到聲明和實體框架
模式是無效的。錯誤: Model1.msl(23,14):錯誤2038:參數DataField的 綁定多個 次。
的PROC:
ALTER PROCEDURE [dbo].[USP_UPSERT_SimpleTableExample]
(
@NaturalKey1 nchar(10),
@NaturalKey2 nchar(10),
@NaturalKey3 nchar(10),
@DataField nchar(10)
)
AS
BEGIN
-- Start Transaction
BEGIN TRAN
MERGE INTO dbo.SimpleTableExample ChangeSet
USING (SELECT @NaturalKey1 as key1,
@NaturalKey2 as key2,
@NaturalKey3 as key3) CurrentSet
ON ChangeSet.NaturalKey1 = CurrentSet.key1 AND
ChangeSet.NaturalKey2 = CurrentSet.key2 AND
ChangeSet.NaturalKey3 = CurrentSet.key3
WHEN MATCHED THEN
UPDATE SET DataField = @DataField
WHEN NOT MATCHED
THEN INSERT VALUES
(@NaturalKey1,
@NaturalKey2,
@NaturalKey3,
@DataField)
OUTPUT INSERTED.SurrogateKey;
COMMIT TRAN
END
和我的測試代碼;
static void Main(string[] args)
{
Class1 c1 = new Class1();
var test = new SimpleTableExample();
test.DataField = "data1";
test.NaturalKey1 = "1";
test.NaturalKey2 = "2";
test.NaturalKey3 = "3";
c1.test(test);
}
public string test(SimpleTableExample ste)
{
ExamplesEntities1 ex1 = new ExamplesEntities1();
ex1.AddToSimpleTableExamples(ste);
ex1.SaveChanges();
Console.WriteLine("SurrogateKey:0", ste.SurrogateKey);
Console.WriteLine("EntityKey:0", ste.EntityKey);
return ste.EntityKey.ToString();
}
好吧,它告訴你,你的EDMX是無效的,甚至給你的行號。我首先看看那裏...... – 2011-06-09 19:53:59
如果你打開EDMX爲XML,你在描述的行上看到了什麼? – 2011-06-09 19:54:31