Closed djlaney3 closed 5 years ago
You should then separate your DTOs for "show data" and "save data". I mean you can create a DTO that is not derived from AuditedEntityDto and use it for the creation form.
I changed my create/update dto to inherit from EntityDto and the dynamic form only shows my custom fields. But, on saving, the audit fields do not get updated. Should they? It seems like the framework does this automatically but I can't get it to work. So my underlying entity inherits from AuditedEntity, but the create/update dto inherits from AuditedEntityDto. Should this the audit fields auto populate?
Create/edit/update DTOs should not derive from audited DTOs. Auditing properties of the entity are automatically managed by the framework. Create properties set on creation, modification properties are set on update. Doesn't that work?
It does seems to work for updates. For creates, my key is a bigint that auto increments. It appears the create dynamic form wants me to put in a value, but of course, the db won't accept it because it is the identity field. How do I set that up properly?
Your Id in the create form should not be required. If you want to use a single DTO for create/update, then make Id nullable (because it should not be set for creation - don't inherit from EntityDto in that case)
Why not getting Identity module as an example: https://github.com/abpframework/abp/tree/master/modules/identity
Maybe I am mis understanding what you are saying. Here are my objects: CreateUpdateCareerDto.cs
[AutoMapTo(typeof(Career))]
[AutoMapFrom(typeof(CareerDto))]
public class CreateUpdateCareerDto : EntityDto<long>
{
[Required]
[StringLength(50)]
public string Name { get; set; }
[StringLength(int.MaxValue)]
public string Note { get; set; }
}
Career.cs --entity
public class Career : AuditedEntity<long>
{
[Required]
[StringLength(50)]
public string Name { get; set; }
[StringLength(int.MaxValue)]
public string Note { get; set; }
}
The Id field shows up on both create and update.
CareerDto
[AutoMapFrom(typeof(Career))]
public class CareerDto : EntityDto<long>
{
public string Name { get; set; }
public string Note { get; set; }
}
Please format code like this:
```c# // Your code ```
CreateUpdateCareerDto
should not inherit EntityDto
.
Ok.. Made that change. Create works fine now. But update is not saving the LastModificationTime or LastModifierId columns. What am I doing wrong there? Previously I said it worked, but I was incorrect. The screen didn't error, but the db was not updated on the audit fields.
Also, CareerDto should inherit from EntityDto
LastModificationTime
should always be set — check properly.LastModifierId
is set if the current user is available.LastModificationTime -> other than looking at the db field, how do I check properly?
Show code for updating.
It is a dynamic form, the framework should handle it, shouldn't it?
[HiddentInput] attribute will hide the Id input box while you are editing the entity. See that example.
Other fields (CreationTime, LastModificatioTime etc.) shouldn't be there anyway.
I'm not seeing how your comment is relevant to my issue. The audit fields are not present and shouldn't be on the edit forms. However, the LastModificationTime isn't being populated under any circumstance, and from what has been shown in this thread, it should be.
I am using a dynamic form that uses a Dto that implements AuditedEntityDto. When the form shows, it shows all the audit fields for input. Are those hideable?
And i just mentioned that dynamic-form will hide the fields that has [HiddentInput] attribute, if you're wondering.
Ok. That can be useful. I'm still trying to figure out why the LastModificationTime won't populate though.
I did another test using the BookStore sample app. It has the same issue. LastModificationTime does not populate on update.
@djlaney3 can you create an issue for "LastModificationTime does not populate on update".
Opened new issue, #579. Closing this one.
I am using a dynamic form that uses a Dto that implements AuditedEntityDto. When the form shows, it shows all the audit fields for input. Are those hideable? It seems that they should auto populate behind the scenes on save. Is this not how that works? Is that feature not available yet?