using FreeSql.DataAnnotations; namespace ToolHub.Models; [Table(Name = "UserToolAccesses")] public class UserToolAccess { [Column(IsIdentity = true, IsPrimary = true)] public int Id { get; set; } public int? UserId { get; set; } // 可为空,支持匿名用户 public int ToolId { get; set; } [Column(StringLength = 50)] public string? SessionId { get; set; } // 会话ID,用于匿名用户跟踪 [Column(StringLength = 45)] public string? IpAddress { get; set; } // IP地址 [Column(StringLength = 500)] public string? UserAgent { get; set; } // 用户代理 [Column(StringLength = 100)] public string? Referer { get; set; } // 来源页面 [Column(StringLength = 20)] public string AccessType { get; set; } = "view"; // view, favorite, share, download public int Duration { get; set; } = 0; // 停留时间(秒) public DateTime CreatedAt { get; set; } = DateTime.Now; // 导航属性 [Navigate(nameof(UserId))] public User? User { get; set; } [Navigate(nameof(ToolId))] public Tool Tool { get; set; } = null!; }