Pomelo.EntityFrameworkCore.MySql
Pomelo.EntityFrameworkCore.MySql copied to clipboard
Missing column problem when adding data
Steps to reproduce
Table
[Table("T_User_Message_PushSettings")]
public class UserMessagePushSettings
{
public long Id { get; set; }
/// <summary>
/// 互动推送
/// </summary>
[Comment("互动推送,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum Interactive { get; set; }
/// <summary>
/// 评论推送
/// </summary>
[Comment("评论推送,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum Comment { get; set; }
/// <summary>
/// 共创邀请推送
/// </summary>
[Comment("共创邀请推送,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum ChatInvite { get; set; }
/// <summary>
/// 创建社区推送
/// </summary>
[Comment("创建社区推送,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum CreateCommunity { get; set; }
/// <summary>
/// 社区新的审批流提醒
/// </summary>
[Comment("社区新的审批流提醒,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum CommunityEvent { get; set; }
/// <summary>
/// 社区新的审批流平票提醒
/// </summary>
[Comment("社区新的审批流平票提醒,0-不推送,1-推送"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum EventTieTicket { get; set; }
/// <summary>
/// 社区消息通知
/// </summary>
[Comment("社区消息通知"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum Community { get; set; }
/// <summary>
/// 系统通知
/// </summary>
[Comment("系统通知"), Column(TypeName = "TINYINT")]
public MessagePushSettingEnum System { get; set; }
}
Enum
public enum MessagePushSettingEnum
{
UnPush = 0,
Push = 1
}
Method
/// <summary>
///
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public async Task SaveMessagePushSettingAsync(MessagePushSettingsDto input)
{
var setting = await _settingsRepository.GetAsync(CurrentUser.Id!.Value);
if (setting == null && !CheckMessagePushValidate(input))
return;
setting ??= new UserMessagePushSettings()
{
Id = 0,
Interactive = MessagePushSettingEnum.Push,
Comment = MessagePushSettingEnum.Push,
ChatInvite = MessagePushSettingEnum.Push,
CreateCommunity = MessagePushSettingEnum.Push,
CommunityEvent = MessagePushSettingEnum.Push,
EventTieTicket = MessagePushSettingEnum.Push,
Community = MessagePushSettingEnum.Push,
System = MessagePushSettingEnum.Push
};
setting.Interactive = input.Interactive;
setting.Comment = input.Comment;
setting.ChatInvite = input.ChatInvite;
setting.CreateCommunity = input.CreateCommunity;
setting.CommunityEvent = input.CommunityEvent;
setting.EventTieTicket = input.EventTieTicket;
if (setting.Id == 0)
{
setting.Id = CurrentUser.Id!.Value;
await _settingsRepository.CreateAsync(setting);
}
else
{
await _settingsRepository.UpdateFieIdsAsync(setting, x => x.Interactive, x => x.Comment, x => x.ChatInvite, x => x.CreateCommunity, x => x.CommunityEvent, x => x.EventTieTicket);
}
}
RepositoryMethod
/// <summary>
/// 添加数据
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
public virtual async Task<T> CreateAsync(T data)
{
var db = await _context.Set<T>().AddAsync(data);
await _context.SaveChangesAsync();
return db.Entity;
}
The issue
When I perform an insert operation, the property CommunityEvent
is not inserted, which causes the property CommunityEvent
to always be the default value of the column when inserting
Print out the execution log as shown below
What's even more strange is that no matter what name I change this property CommunityEvent
to, it will always be ignored when this column is inserted, but it is normal when it is updated
Am I wrong in which position?
Further technical details
MySQL version: 8.0.28 Operating system: windows 10 Pomelo.EntityFrameworkCore.MySql version:6.0.2 Microsoft.AspNetCore.App version: .net 6