此章节讲述Add添加数据的操作。
首先在xaml界面上添加一个Add Button
<Button Content="Add Event" Height="23" Name="button1" Width="75" Click="button1_Click" />
在点击该按钮的是触发事件:
private void button1_Click(object sender, System.Windows.RoutedEventArgs e)
{
EventManagerDomainContext ctx = new EventManagerDomainContext();
Event newEvent = new Event
{
EventTitle = "<Title>",
EventVenueName = "<Venue>",
EventDescription = "<Description>",
EventStartDate = DateTime.Now.Date,
EventEndDate = DateTime.Now.Date
};
ctx.Events.Add(newEvent);
ctx.SubmitChanges((op) =>
{
if (!op.HasError)
{
NavigateToEditEvent(newEvent.EventID);
}
},null
);
}
这里的(op)=>表示的意思为执行完SubmitChanges后,执行下一步的代码。