This question is locked. New answers and comments are not allowed.
Hi,
I've created a Domain Model from my database. I'm having troubles with my many-to-many relations...
I have the following entities:
- Product
- Keyword
There is an association between them:
- ProductsReferenceKeywords (ZeroMany, ZeroMany)
So, there is a Join table in my database. Inserting records is okay, but deleting records won't work.
I've switched on the 'Managed' option on the Product entity.
In SQL Server there are relationships between the tables and also CASCADE UPDATE / DELETE is switched on.
This is the code for deleting an association:
Nothing happens with this solution.
Anyone has an idea?
Also tried to remove the Product object from the Keyword collection...
Regards,
Daniel
I've created a Domain Model from my database. I'm having troubles with my many-to-many relations...
I have the following entities:
- Product
- Keyword
There is an association between them:
- ProductsReferenceKeywords (ZeroMany, ZeroMany)
So, there is a Join table in my database. Inserting records is okay, but deleting records won't work.
I've switched on the 'Managed' option on the Product entity.
In SQL Server there are relationships between the tables and also CASCADE UPDATE / DELETE is switched on.
This is the code for deleting an association:
/// <summary>
/// Delete a keyword from a product
/// </summary>
/// <param name="keywordid"></param>
/// <param name="productid"></param>
/// <returns></returns>
public
bool
DeleteKeywordFromProduct(Guid keywordid, Guid productid) {
bool
result =
false
;
try
{
Product p = context.Products.Where(x => x.ProductId == productid).FirstOrDefault();
Keyword k = context.Keywords.Where(x => x.KeywordId == keywordid).FirstOrDefault();
p.Keywords.Remove(k);
context.SaveChanges();
result =
true
;
}
catch
(Exception ex)
{
throw
ex;
}
return
result;
}
Nothing happens with this solution.
Anyone has an idea?
Also tried to remove the Product object from the Keyword collection...
Regards,
Daniel