0
我有以下對象模型:實體框架查詢不產生
[Table("APA_QuestionProduct")]
public class QuestionProduct
{
[Key, ForeignKey("Question"), Column(Order=0)]
public int QuestionID { get; set; }
[ForeignKey("QuestionID")]
public Question Question { get; set; }
[Key, ForeignKey("Product"), Column(Order=1)]
public int ProductID { get; set; }
[ForeignKey("ProductID")]
public Product Product { get; set; }
}
表:
USE [qbm]
GO
/****** Object: Table [dbo].[APA_QuestionProduct] Script Date: 5/21/2013 6:52:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[APA_QuestionProduct](
[QuestionID] [int] NOT NULL,
[ProductID] [int] NOT NULL,
CONSTRAINT [PK_APA_QuestionProduct] PRIMARY KEY CLUSTERED
(
[QuestionID] ASC,
[ProductID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[APA_QuestionProduct] WITH CHECK ADD CONSTRAINT [FK_APA_QuestionProduct_APA_Product] FOREIGN KEY([ProductID])
REFERENCES [dbo].[APA_Product] ([ProductID])
GO
ALTER TABLE [dbo].[APA_QuestionProduct] CHECK CONSTRAINT [FK_APA_QuestionProduct_APA_Product]
GO
ALTER TABLE [dbo].[APA_QuestionProduct] WITH CHECK ADD CONSTRAINT [FK_APA_QuestionProduct_APA_Question] FOREIGN KEY([QuestionID])
REFERENCES [dbo].[APA_Question] ([QuestionID])
GO
ALTER TABLE [dbo].[APA_QuestionProduct] CHECK CONSTRAINT [FK_APA_QuestionProduct_APA_Question]
GO
所以在桌子後面僅具有2外鍵(即也主鍵)。我的問題對象有一個產品列表。當我更新的產品ID外鍵並調用「的SaveChanges」對db不生成查詢/更新背景:
question.Products[1].ProductID = 4;
db.Entry(question.Products[1]).State = EntityState.Modified;
db.SaveChanges();
我看了InteliTrace檢查查詢,但沒有查詢叫過我QuestionProduct表,即使我的QuestionProduct對象已更改。爲什麼表格沒有更新?沒有錯誤被拋出。