Hi guys,
I'm having trouble inserting a new LinqToSql object over WCF.
What I'm doing is just sending an Orders Batch to the service. Inside the batch are Orders that have already been sent previously. When I do
data.batches.InsertOnSubmit(newbatch)
I get a sql error:
"Violation of PRIMARY KEY constraint 'PK_HTOrder'. Cannot insert duplicate key in object 'dbo.HTOrder'. The statement has been terminated."
Here's the code where it inserts the batch (obj):
Dim tableproperty As PropertyInfo = dataProperties.Find(Function(p As PropertyInfo) (p.PropertyType.FullName.Contains("[" + obj.GetType.FullName + ",")))
Dim tableMethod As MethodInfo = tableproperty.GetGetMethod()
Dim tab As Object = tableMethod.Invoke(data, New Object() {})
tab.GetType.GetMethod("InsertOnSubmit", New Type() {obj.GetType}).Invoke(tab, New Object() {obj})
data.SubmitChanges(ConflictMode.FailOnFirstConflict)
Dim checkMatch As Object = GetMatchingEntities(obj, data).SingleOrDefault
If checkMatch Is Nothing Then Throw New UpdateNotVerfiedExecption(obj)
Return checkMatch
I've tried attaching the parent to the context first, but it naturally told me it existed when I tried to Insert it right after. Attaching the child orders doesn't seem to help either.
Any suggestions?
Thanks,
Del