linq to sql - [error] An attempt was made to remove a relationship between a [mastertable] and a [detailtable]. However, one of the relationship's foreign keys (detailtable.foreignkey1) cannot be set to null


System.InvalidOperationException: An attempt was made to remove a relationship between a Order and a OrderDetail. However, one of the relationship's foreign keys (OrderDetail.OrderID) cannot be set to null.
To fix this we need to indicate to the model that we want to delete the OrderDetail when it's OrderID is set to null. Unfortunately this cannot be done in the O/R designer so you have to open the model in an XML editor. Fortunately, once you change it the designer won't mess with it again unless you remove the class completely. Open the dbml file with the XML Editor (just right-click on it an select "Open with...") and locate the XML that describes the OrderDetail class. Notice the association under the OrderDetail table:
<Table Name="dbo.OrderDetail" Member="OrderDetails">
  <Type Name="OrderDetail">
    <Column Name="OrderDetailID" Type="System.Int32" DbType="Int NOT NULL IDENTITY" 
            IsPrimaryKey="true" IsDbGenerated="true" CanBeNull="false" />
    <Column Name="OrderID" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    <Column Name="ProductID" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    <Column Name="Quantity" Type="System.Int32" DbType="Int NOT NULL" CanBeNull="false" />
    <Column Name="Price" Type="System.Decimal" DbType="Money" CanBeNull="true" />
    <Column Name="Modified" Type="System.Data.Linq.Binary" DbType="rowversion NOT NULL" 
            CanBeNull="false" IsVersion="true" />
    <Association Name="Order_OrderDetail" Member="Order" ThisKey="OrderID" 
                 Type="Order" IsForeignKey="true"/>
     Name="Product_OrderDetail" Member="Product" ThisKey="ProductID" 
                 Type="Product" IsForeignKey="true" />
  Type>
We need to add an attribute here called DeleteOnNull and set it to true in order to be able to delete a child row independently in the database when calling SubmitChanges(). Once we make this change we can now delete just a single OrderDetail from the grid and save normally:
<Association Name="Order_OrderDetail" Member="Order" ThisKey="OrderID" Type="Order" 
             IsForeignKey="true" DeleteOnNull="true"/>
The other option to fix this issue is to modify the Delete Rule to "Cascade" on the relationship in the database. In that case the designer correctly infers this attribute on the association.

http://blogs.msdn.com/bethmassi/archive/2008/02/19/one-to-many-master-detail-forms-with-linq-to-sql.aspx

not: 1. yol sorunu çözdü.

not 2. eğer ilişki prod, usagearea, prod_usagearea biçimindeyse;

[Association(Name="Prod_Prod_UsageArea", Storage="_Prod", ThisKey="ProdID", OtherKey="ProdID", IsForeignKey=true, DeleteOnNull = true)]

[Association(Name = "UsageArea_Prod_UsageArea", Storage = "_UsageArea", ThisKey = "UsageAreaID", OtherKey = "UsageAreaID", IsForeignKey = true, DeleteOnNull = true)]

prod_usagearea tablosu:
prodid (primarykey, int, not null)
usageareaid (primarykey, int, not null)

search this blog (most likely not here)