Hi there. I am doing small Silverlight app which will allow users to Create orders. I have created Linq 2 SQL dbml and dragged there my database tables, "Orders" and "OrderLines" , there is an association between them. Order.ID ~ OrderLine.OrderID, so then i created DomainService for my tables, where i enabled client access, it generated for me the methods, Insert,Update,Delete,Get, for Orders and OrderLines, now i am creating New Order from my silverlight application, the usercontrol looks like this:
public partial class NewOrderView : UserControl
{
public ObservableCollection<OrderLine> OrderLines { get; set; }
public NewOrderView()
{
InitializeComponent();
OrderLines = new ObservableCollection<OrderLine>();
dataGrid.ItemsSource = OrderLines;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var order = new Order();
foreach (var orderLine in OrderLines)
{
order.OrderLines.Add(orderLine);
}
order.CompanyId = int.Parse(StaticContainer.CurrentUser.CompanyId.ToString());
order.CreationDate = DateTime.Now;
order.Status = "შეკვეთილი";
order.Id = 1;
var ctx = new EntreeDomainContext();
ctx.Orders.Add(order);
ctx.SubmitChanges();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
StaticContainer.Navigation.Back();
}
private void Button_Click_2(object sender, RoutedEventArgs e)
{
StaticContainer.Navigation.LogOut();
}
private void AddProduct(object sender, ProductAdditionEventHandlerArgs args)
{
var result = OrderLines.Where(x => x.Item.itmKEY == args.Product.itmKEY).FirstOrDefault();
if(result==null)
OrderLines.Add(new OrderLine(){Item = args.Product});
}
}
and Domain Service Method:
public void InsertOrder(Order order)
{
Context.Orders.InsertOnSubmit(order);
Context.SubmitChanges();
}
i have put here break point, and the thread comes here , and everything dones ok. but after that in the database no order and no orderline exist. and output writes : "A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.Linq.dll"
what can i do? please help, and thank you.