ASP.net应用程序建议需要
问题描述:
即时biulding连接到数据库的ASP.net应用程序。数据库设计如下ASP.net应用程序建议需要
**Users Table**
UserID `(PK) autonumber`
Username
**Question Table**
QuestionID `(PK) autonumber`
QuestionNumber
QuestionText
**Questionnaire Table**
QuestionnaireID `(PK) autonumber`
UserID `(FK) User Table`
Date
**Feedback Table**
FeedbackID `(PK) autonumber`
QuestionnaireID `(FK) Questionnaire Table`
QuestionID `(FK) Questions Table`
Answer
Comment
请问我可以告诉我如何将数据插入问卷表和反馈表。我知道问卷表需要先更新。但问卷ID与反馈表相关联,那么如何更新两个表?
答
看看使用Linq2Sql(在你的项目中添加一个新的Linq到Sql Classes的dbml文件,并将你的表从你的服务器扩展器拖到它上面),它会将你的表映射到类和一个datacontext,你可以用它来创建新的数据对象来更新你的表。它会自动跟踪并插入必要的行,并管理自己的博客中它们之间的关系
DataContext db = new DataContext();
Questionnaire q = new Questionnaire();
q.UserId = 1234;
Feedback f = new Feedback();
f.Questionnaire = q;
db.Feedbacks.InsertOnSubmit(f);
db.SubmitChanges();
一个伟大的地方开始与斯科特谷的介绍
http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx
+1 ...的博客真棒 – c11ada 2010-03-24 19:02:34