question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with update master detail entity

See original GitHub issue

Hi, I have a problem with an update in a master-detail entity, master is News and detail is ContentRelations. and I user CRUDAsyuncService and Update method and pass it master entity. this is my code:

    public class News : Content
    {
        public string Description { get; set; }
        public string Body { get; set; }
        public DateTime PublishDate { get; set; }
        public bool IsPromoted { get; set; }
        public DateTime? PromotionExpireDate { get; set; }
    }

    public abstract class Content : FullAuditedEntity<int, User>, IPassivable, INeedCrudPermissions
    {
        public string Title { get; set; }
        public bool IsActive { get; set; }
        public virtual ContentProtection ContentProtection { get; set; }
        public virtual ICollection<ContentRelation> ContentRelations { get; set; } = new 
        List<ContentRelation>();
    }

I got this error:

e.InnerException {System.Data.SqlClient.SqlException (0x80131904): Cannot insert explicit value for identity column in table ‘ContentRelations’ when IDENTITY_INSERT is set to OFF.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
malimingcommented, Mar 5, 2019

@mehdih66 If you want to update entities and child entities within a single method.

Fake code:

public override News Update(News input)
{
	var news = await Repository.GetAsync(input.Id);
	ObjectMapper.Map(input, news); //ignore the fileRelations.

	foreach (var file in input.fileRelations)
	{
		var dbFile = await Repository.GetAsync(file.Id);
		ObjectMapper.Map(file, dbFile);
	}
	
	return news;
}
0reactions
mehdihadelicommented, Mar 6, 2019

Ok thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to update master detail in Entity Framework using ...
The problem is : the master is updated,new details is added,. but the updated detail not persistence.
Read more >
Refresh a master/detail form when an insert/update occurs
I use Oracle ADF with Jdeveloper 10.1.3.4 and EJBs for my datacontrol. I have two entities which have a master/ detail relationship...
Read more >
Power Tools Master - Detail problems #11379
This entity is working fine (it just has a few String properties). Next, I created a Master/Details entity named "SalesRegion". The intention is ......
Read more >
Error when dragging the details table, en Master / detail
I make a new project windows Forms (.Net Fframework). I add a new element: ADO.Net Entity Data Model, database Northwind.
Read more >
Advance Master Detail CRUD in MVC ASP.NET CORE 6 ...
In Here , I have used advanced features of Entity framework core and ... type of master detail screens like Salesinvoice, Purchase order, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found