This is a public service announcement.
If you’ve got a class like this:
[DataContract(Namespace = "")] [XmlRoot(Namespace = "")] [Table(Name = "dbo.PurchaseOrder")] public class PurchaseOrder : DomainBase { [DataMember] [Column(IsPrimaryKey = true, IsDbGenerated = false, CanBeNull = false)] public Guid Id { get; set; } [DataMember] [Association(Name = "FK_PurchaseOrder_PurchaseOrderDetails", OtherKey = "PurchaseOrderId", Storage = "details")] public IListDetails { get { return this.details; } set { SetOrAssign(ref this.details, value); } } private EntitySet details; }
and a class like this:
[DataContract(Namespace = "")] [XmlRoot(Namespace = "")] [Table(Name = "dbo.PurchaseOrderDetail")] public class PurchaseOrderDetail { [DataMember] [Column(IsPrimaryKey = true, IsDbGenerated = false, CanBeNull = false)] public Guid Id { get; set; } [DataMember, Column] public Guid PurchaseOrderId { get; set; } [DataMember, Column] public Guid ItemId { get; set; } [DataMember] [Association(Name = "FK_PurchaseOrderDetail_PurchaseOrder", Storage = "purchaseOrder", ThisKey = "PurchaseOrderId", IsForeignKey = true)] public PurchaseOrder PurchaseOrder { get { return this.purchaseOrder.Entity; } set { this.purchaseOrder.Entity = value; } } private EntityRefpurchaseOrder; }
and you’re getting highly bizarre results when you try to call your web service like mysterious second calls even though you know you’re only calling it once, try to remember that Linq-To-Sql still doesn’t support back references like other ORMs you’ve loved before. Delete the reference to the parent object from the child object (in this case, that sneaky little purchase order on the purchase order detail) and rejoice in the fact that all is right with the world again. Go drink beer, eat sausage and terrorize puppies (or whatever it is you do for relaxation).
I don’t know why I can’t get this through my thick skull. Just because I expect something to act a logical certain way doesn’t mean it will.