0

I would like to choose the connection string relative to an attribute of the User class that connected. `

public class ApplicationUser : IdentityUser, IAuditableEntity
    {
        public virtual string FriendlyName
        {
            get
            {
                string friendlyName = string.IsNullOrWhiteSpace(FullName) ? UserName : FullName;

                if (!string.IsNullOrWhiteSpace(Caisse))
                    friendlyName = $"{Caisse} {friendlyName}";

                return friendlyName;
            }
        }


        public string Caisse { get; set; }
        public string FullName { get; set; }
        public string Configuration { get; set; }
        public bool IsEnabled { get; set; }
        public bool IsLockedOut => this.LockoutEnabled && this.LockoutEnd >= DateTimeOffset.UtcNow;

        public string CreatedBy { get; set; }
        public string UpdatedBy { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime UpdatedDate { get; set; }



        /// <summary>
        /// Navigation property for the roles this user belongs to.
        /// </summary>
        public virtual ICollection<IdentityUserRole<string>> Roles { get; set; }

        /// <summary>
        /// Navigation property for the claims this user possesses.
        /// </summary>
        public virtual ICollection<IdentityUserClaim<string>> Claims { get; set; }

        /// <summary>
        /// Demo Navigation property for orders this user has processed
        /// </summary>
        public ICollection<Order> Orders { get; set; }
    }

`If the name of the "Caisse" is the same as the name of the Connection String, the GetConnectionString is equal to the name of the "Caisse".

`

"ConnectionStrings": {
    "DefaultConnection": "Server=.\\SQLEXPRESS; Database=Ctisn; Trusted_Connection=True; MultipleActiveResultSets=True; User ID=SA; Password=123;",
    "MECLESINE": "Server=myServer; Port=3306; Database=myDB; User ID=appuser; Password=appuser;",
    "FONEES": "Server=myServer; Port=3306; Database=myDB; User ID=appuser; Password=appuser;",
    "MECFP": "Server=myServer; Port=3306; Database=myDB; User ID=appuser; Password=appuser;",
    "MECCT": "Server=myServer; Port=3306; Database=myDB; User ID=appuser; Password=appuser;",
    "JSR": "Server=myServer; Port=3306; Database=myDB; User ID=appuser; Password=appuser;",


  },

`

  • I refer you to this question [How to have different connection string for different users in Entity Framework](https://stackoverflow.com/questions/14480646/how-to-have-different-connection-string-for-different-users-in-entity-framework) – MahdiShams Oct 31 '22 at 12:09

0 Answers0