Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Tenant Context missing tables? #1753


User avatar
0
carelearning created

Hello,

We recently tried to implement signalR change notifications (following [http://www.aspnetboilerplate.com/Pages/Documents/SignalR-Integration]) )with host and tenant dbContexts. When we ran, there were errors: UserFriendsCache: {"Invalid object name 'dbo.AppFriendships'."} and also the same error for table AppChatMessages. A screenshot of this error is attached. I apologize if file is blurry, but it would not let me upload a larger file. If it is hard to read, tell me and I can upload multiple images of error.

When we manually create those tables in the tenant DB, then the error goes away. Is this the correct fix?

<ins>Background Information:</ins> in our layout page:

<script src="~/wwwroot/js/jquery.signalR-2.2.1.js" type="text/javascript"></script>
  <script src="~/signalr/hubs" type="text/javascript"></script>    
  // ..a few other script files
  <script src="~/wwwroot/js/abp.signalr.js" type="text/javascript"></script>

The ChangeNotificationHub.cs file looks like this:

namespace MyCompanyName.AbpZeroTemplate.Web.Hubs
{
    using Abp.Dependency;
    using Microsoft.AspNet.SignalR;
    using Microsoft.AspNet.SignalR.Hubs;
    using System.Threading.Tasks;

    [HubName("changeNotify")]
    public class ChangeNotificationHub: Hub, ITransientDependency
    {
        public Task Deregister(string groupName)
        {
            return Groups.Remove(Context.ConnectionId, groupName);
        }

        public Task Register(string groupName)
        {
            return Groups.Add(Context.ConnectionId, groupName);
        }

        public void Save(string groupName)
        {
            Clients.OthersInGroup(groupName).changePending();
        }
    }
}

and the changeNotification.js file looks like this:

(function () {
    var changeNotifyHub = $.connection.changeNotify;

    // Connected
    abp.event.on('abp.signalr.connected', function () {
        changeNotifyHub.server.register(ams.getCurrentUrl());
    });

    // Disconnected
    abp.event.on('abp.signalr.disconnected', function () {
        changeNotifyHub.server.deregister(ams.getCurrentUrl());
    });

    changeNotifyHub.client.changePending = function () {
        $('#saveAlert').toggleClass('hidden');
        // buttonGroup.state = reset;
    };

    $.connection.hub.start();
})();

Thank you again for your help. Please let me know if you need any more information.


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I think you have added ChatMessage and Friendship entities to your project. If so, you need to add a code firs migration as well. And then update the database.

    Adding those tables is not the right way. I suggest you to delete those tables and add code first migrations, then update your database.

    Please let me know if you need help on doing that.

  • User Avatar
    0
    carelearning created

    Hello,

    Thank you for your response. We do not use the ChatMessage and Friendship tables. They are not referenced anywhere in our code. We do not get this error until we include the javascript files in our layout. When we drop the tables and try to add a migration, it does not find find these tables to add. To use signalR in abpZero template, are these tables required? Is there some sort of dependenct injection requirement? We can manually create a migration instead of adding the table manually through SQL. Is that what you mean?

    For more background, our Tenent DB Context File looks like this:

    namespace MyCompanyName.AbpZeroTemplate.EntityFramework
    {
    //    using statments;
    
        public class AbpZeroTemplateTenantDbContext : AbpZeroTenantDbContext<Role, User>
        {
            public virtual IDbSet<Department> Departments { get; set; }
            public virtual IDbSet<Enrollment> Enrollments { get; set; }
    
            public AbpZeroTemplateTenantDbContext() : base("Tenant")
            {
                
            }
    
            public AbpZeroTemplateTenantDbContext(string nameOrConnectionString)
                : base(nameOrConnectionString)
            {
    
            }
    
            /* This constructor is used in tests to pass a fake/mock connection.
             */
            public AbpZeroTemplateTenantDbContext(DbConnection dbConnection)
                : base(dbConnection, true)
            {
    
            }
    
            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                base.OnModelCreating(modelBuilder);
    
                modelBuilder.Configurations.Add(new DepartmentConfiguration());
                modelBuilder.Configurations.Add(new EnrollmentConfiguration());
            }
        }
    }
    

    and the error we are getting is attached.

    Thank you again for your help.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I got it. If you dont want to use chat feature and those tables you dont need to add migration.

    Bu i think you have added some code which is chat specific to your project. Those tables are not required to use signalr.

    You need to remove those codes ( both from server side and client side )