修改计算列
							parent
							
								
									fca6be727c
								
							
						
					
					
						commit
						6d5f73a415
					
				| 
						 | 
					@ -32,6 +32,7 @@ namespace IRaCIS.Core.Domain.Models
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public int TotalMillisecondsInterval { get; set; }
 | 
					        public int TotalMillisecondsInterval { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public DateTime UploadStartTime { get; set; }
 | 
					        public DateTime UploadStartTime { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,6 +10,7 @@ using Microsoft.EntityFrameworkCore.ChangeTracking;
 | 
				
			||||||
using System.Reflection;
 | 
					using System.Reflection;
 | 
				
			||||||
using EntityFramework.Exceptions.SqlServer;
 | 
					using EntityFramework.Exceptions.SqlServer;
 | 
				
			||||||
using IRaCIS.Core.Domain.Share;
 | 
					using IRaCIS.Core.Domain.Share;
 | 
				
			||||||
 | 
					using IRaCIS.Core.Infra.EFCore.ValueGenerator;
 | 
				
			||||||
using MassTransit;
 | 
					using MassTransit;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
 | 
					using Microsoft.EntityFrameworkCore.Infrastructure;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore.Metadata;
 | 
					using Microsoft.EntityFrameworkCore.Metadata;
 | 
				
			||||||
| 
						 | 
					@ -20,7 +21,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public class IRaCISDBContext : DbContext
 | 
					    public class IRaCISDBContext : DbContext
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        public  readonly IUserInfo _userInfo;
 | 
					        public readonly IUserInfo _userInfo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 在控制台
 | 
					        // 在控制台
 | 
				
			||||||
        //public static readonly ILoggerFactory MyLoggerFactory    = LoggerFactory.Create(builder => { builder.AddConsole(); });
 | 
					        //public static readonly ILoggerFactory MyLoggerFactory    = LoggerFactory.Create(builder => { builder.AddConsole(); });
 | 
				
			||||||
| 
						 | 
					@ -33,7 +34,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
            //_configuration = configuration;
 | 
					            //_configuration = configuration;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
         
 | 
					
 | 
				
			||||||
        //比数据库上下文构造函数先执行 不能构造函数注入的方式使用配置文件
 | 
					        //比数据库上下文构造函数先执行 不能构造函数注入的方式使用配置文件
 | 
				
			||||||
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 | 
					        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					@ -66,13 +67,12 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
        #endregion
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        protected override void OnModelCreating(ModelBuilder modelBuilder)
 | 
					        protected override void OnModelCreating(ModelBuilder modelBuilder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            //modelBuilder.Entity<User>().Property(t => t.FullName) .HasDefaultValueSql("[LastName] + ' / ' + [FirstName]");
 | 
					            //modelBuilder.Entity<User>().Property(t => t.FullName) .HasDefaultValueSql("[LastName] + ' / ' + [FirstName]");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //code first  must  migration    dbfirst  must config  in db
 | 
					 | 
				
			||||||
            modelBuilder.Entity<StudyMonitor>().Property(e => e.TotalMillisecondsInterval).HasComputedColumnSql("datediff(MS,UploadStartTime,UploadFinishedTime)");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (_userInfo.IsEn_Us)
 | 
					            if (_userInfo.IsEn_Us)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.Value));
 | 
					                modelBuilder.Entity<Dictionary>().Property(t => t.MappedValue).HasColumnName(nameof(Domain.Models.Dictionary.Value));
 | 
				
			||||||
| 
						 | 
					@ -238,7 +238,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        #region QA
 | 
					        #region QA
 | 
				
			||||||
       
 | 
					
 | 
				
			||||||
        public virtual DbSet<QCChallengeDialog> QCChallengeDialog { get; set; }
 | 
					        public virtual DbSet<QCChallengeDialog> QCChallengeDialog { get; set; }
 | 
				
			||||||
        public virtual DbSet<QANotice> QATemplateDictionary { get; set; }
 | 
					        public virtual DbSet<QANotice> QATemplateDictionary { get; set; }
 | 
				
			||||||
        public virtual DbSet<QCChallenge> QCChallenge { get; set; }
 | 
					        public virtual DbSet<QCChallenge> QCChallenge { get; set; }
 | 
				
			||||||
| 
						 | 
					@ -328,7 +328,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
        #region 重写savechange方式 统一增加审计信息 CreateUserId CreateTime UpdateTime UpdateUserId  可用事件绑定的方式UpdateAuitUser
 | 
					        #region 重写savechange方式 统一增加审计信息 CreateUserId CreateTime UpdateTime UpdateUserId  可用事件绑定的方式UpdateAuitUser
 | 
				
			||||||
        private void UpdateAuditInfo()
 | 
					        private void UpdateAuditInfo()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          
 | 
					
 | 
				
			||||||
            ChangeTracker.DetectChanges(); // Important!
 | 
					            ChangeTracker.DetectChanges(); // Important!
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            //// 获取所有更改,删除,新增的实体,但排除审计实体(避免死循环)
 | 
					            //// 获取所有更改,删除,新增的实体,但排除审计实体(避免死循环)
 | 
				
			||||||
| 
						 | 
					@ -350,7 +350,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
                            updateEntity1.UpdateUserId = _userInfo.Id;
 | 
					                            updateEntity1.UpdateUserId = _userInfo.Id;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        if(t.Entity is ISoftDelete updateEntity2)
 | 
					                        if (t.Entity is ISoftDelete updateEntity2)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
                            if (updateEntity2.IsDeleted == true)
 | 
					                            if (updateEntity2.IsDeleted == true)
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
| 
						 | 
					@ -374,7 +374,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
                            {
 | 
					                            {
 | 
				
			||||||
                                addEntity.CreateTime = DateTime.UtcNow.AddHours(8);
 | 
					                                addEntity.CreateTime = DateTime.UtcNow.AddHours(8);
 | 
				
			||||||
                            }
 | 
					                            }
 | 
				
			||||||
                            
 | 
					
 | 
				
			||||||
                            addEntity.CreateUserId = _userInfo.Id;
 | 
					                            addEntity.CreateUserId = _userInfo.Id;
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -395,7 +395,7 @@ namespace IRaCIS.Core.Infra.EFCore
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
           
 | 
					
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        #endregion
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,31 @@
 | 
				
			||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using IRaCIS.Core.Domain.Models;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.ChangeTracking;
 | 
				
			||||||
 | 
					using Microsoft.EntityFrameworkCore.ValueGeneration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace IRaCIS.Core.Infra.EFCore.ValueGenerator
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    public class UploadTotalMillisecondsInterval : ValueGenerator<int>
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //code first  must  migration    dbfirst  must config  in db and also need config in code
 | 
				
			||||||
 | 
					        //modelBuilder.Entity<StudyMonitor>().Property(e => e.TotalMillisecondsInterval).HasComputedColumnSql("datediff(MS,UploadStartTime,UploadFinishedTime)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //modelBuilder.Entity<StudyMonitor>().Property(e => e.TestInterval).ValueGeneratedOnAddOrUpdate().HasDefaultValueSql("datediff(MS,UploadStartTime,UploadFinishedTime)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        public override int Next(EntityEntry entry)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (entry.Entity is StudyMonitor entity)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return (entity.UploadFinishedTime - entity.UploadStartTime).Milliseconds;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                throw new ArgumentException("ValueGenerator用在了不适合的实体");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        public override bool GeneratesTemporaryValues => false;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,5 @@
 | 
				
			||||||
using IRaCIS.Core.Domain.Models;
 | 
					using IRaCIS.Core.Domain.Models;
 | 
				
			||||||
 | 
					using IRaCIS.Core.Infra.EFCore.ValueGenerator;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
 | 
					using Microsoft.EntityFrameworkCore.Metadata.Builders;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,11 +12,13 @@ namespace IRaCIS.Core.Infra.EFCore.EntityConfigration
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public void Configure(EntityTypeBuilder<StudyMonitor> builder)
 | 
					        public void Configure(EntityTypeBuilder<StudyMonitor> builder)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
         //   builder
 | 
					            //   builder
 | 
				
			||||||
         // .HasMany(s => s.TrialSiteUserList)
 | 
					            // .HasMany(s => s.TrialSiteUserList)
 | 
				
			||||||
         //.WithOne(c => c.DicomStudy)
 | 
					            //.WithOne(c => c.DicomStudy)
 | 
				
			||||||
         //.HasForeignKey(s => new { s.TrialId, s.SiteId })
 | 
					            //.HasForeignKey(s => new { s.TrialId, s.SiteId })
 | 
				
			||||||
         //.HasPrincipalKey(c => new { c.TrialId, c.SiteId });
 | 
					            //.HasPrincipalKey(c => new { c.TrialId, c.SiteId });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            builder.Property(e => e.TotalMillisecondsInterval).HasValueGenerator<UploadTotalMillisecondsInterval>().ValueGeneratedOnAdd();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            builder
 | 
					            builder
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue