Skip to content

Instantly share code, notes, and snippets.

@hikalkan
Last active June 11, 2016 20:48
Show Gist options
  • Save hikalkan/e035271493fa9fbd7fa026d44c690aa9 to your computer and use it in GitHub Desktop.
Save hikalkan/e035271493fa9fbd7fa026d44c690aa9 to your computer and use it in GitHub Desktop.
DbContextTypeMatcher test
using System;
using System.Collections.Generic;
using System.Linq;
using Abp.Collections.Extensions;
using Abp.Dependency;
using Abp.Domain.Uow;
using Abp.EntityFramework.Repositories;
using Abp.MultiTenancy;
namespace Abp.EntityFramework
{
public class MyDbContextTypeMatcher : IDbContextTypeMatcher
{
private readonly ICurrentUnitOfWorkProvider _currentUnitOfWorkProvider;
private readonly Dictionary<Type, List<Type>> _dbContextTypes;
public MyDbContextTypeMatcher(ICurrentUnitOfWorkProvider currentUnitOfWorkProvider)
{
_currentUnitOfWorkProvider = currentUnitOfWorkProvider;
_dbContextTypes = new Dictionary<Type, List<Type>>();
}
public virtual void Add(Type sourceDbContextType, Type targetDbContextType)
{
if (!_dbContextTypes.ContainsKey(sourceDbContextType))
{
_dbContextTypes[sourceDbContextType] = new List<Type>();
}
_dbContextTypes[sourceDbContextType].Add(targetDbContextType);
}
public virtual Type GetConcreteType(Type sourceDbContextType)
{
//TODO: This can also get MultiTenancySide to filter dbcontexes
//TODO: Can be optimized by extracting/caching MultiTenancySideAttribute attributes for DbContexes.
//Get possible concrete types for given DbContext type
var allTargetTypes = _dbContextTypes.GetOrDefault(sourceDbContextType);
if (allTargetTypes.IsNullOrEmpty())
{
//Not found any target type, return the given type if it's not abstract
if (sourceDbContextType.IsAbstract)
{
throw new AbpException("Could not find a concrete implementation of given DbContext type: " + sourceDbContextType.AssemblyQualifiedName);
}
return sourceDbContextType;
}
if (allTargetTypes.Count == 1)
{
//Only one type does exists, return it
return allTargetTypes[0];
}
//Will decide the target type with current UOW, so it should be in a UOW.
if (_currentUnitOfWorkProvider.Current == null)
{
throw new AbpException("GetConcreteType method should be called in a UOW.");
}
var currentTenancySide = _currentUnitOfWorkProvider.Current.GetTenantId() == null
? MultiTenancySides.Host
: MultiTenancySides.Tenant;
var multiTenancySideContexes = allTargetTypes.Where(type =>
{
var attrs = type.GetCustomAttributes(typeof(MultiTenancySideAttribute), true);
if (attrs.IsNullOrEmpty())
{
return false;
}
return ((MultiTenancySideAttribute)attrs[0]).Side.HasFlag(currentTenancySide);
}).ToList();
//Try to get the DbContext which is for current multitenancy side.
if (multiTenancySideContexes.Count == 1)
{
return multiTenancySideContexes[0];
}
//Try to get the DbContext which not defined AutoRepositoryTypesAttribute
var defaultRepositoryContexes = allTargetTypes.Where(type => !type.IsDefined(typeof(AutoRepositoryTypesAttribute), true)).ToList();
if (defaultRepositoryContexes.Count == 1)
{
return defaultRepositoryContexes[0];
}
//Generating exception
if (multiTenancySideContexes.Count > 1)
{
throw new AbpException(string.Format(
"Found more than one concrete type for given DbContext Type ({0}) define MultiTenancySideAttribute with {1}. Found types: {2}.",
sourceDbContextType,
currentTenancySide,
multiTenancySideContexes.JoinAsString(", ")
));
}
throw new AbpException(string.Format(
"Found more than one concrete type for given DbContext Type ({0}) but none of them defines MultiTenancySideAttribute with {1}. Found types: {2}.",
sourceDbContextType,
currentTenancySide,
multiTenancySideContexes.JoinAsString(", ")
));
}
}
}
@hikalkan
Copy link
Author

hikalkan commented May 25, 2016

Copy this class into your EntityFramework project and then in your Entity Framework module's PreInitialize method, add the following line:

Configuration.ReplaceService<IDbContextTypeMatcher, MyDbContextTypeMatcher>();

@Sampath-Lokuge
Copy link

As I mentioned on the forum post where I do have 2 module's on the Entity Framework.One is "IPDataModule " and "IPLegacyDataModule".So which "PreInitialize method" should I use or Am I wrong here ?

@Sampath-Lokuge
Copy link

Now it's giving this error:

connection string :

<add name="Default" connectionString="Server=localhost; Database=IP;Trusted_Connection=True;" providerName="System.Data.SqlClient" />

Stack trace

WARN  2016-05-26 01:17:32,288 [5    ] Abp.BackgroundJobs.BackgroundJobManager  - Castle.MicroKernel.ComponentActivator.ComponentActivatorException: ComponentActivator: could not instantiate Joshi.IP.EntityFramework.IpDbContext ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.SqlServer.SqlProviderServices.<>c__DisplayClass33.<UsingConnection>b__32()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action`1 act)
   at System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act)
   at System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript)
   at System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection)
   at System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()
   at System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection)
   at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
   at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
   at System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
   at System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState)
   at System.Data.Entity.Database.Create(DatabaseExistenceState existenceState)
   at System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context)
   at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
   at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
   at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
   at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
   at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
   at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
   at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
   at Abp.EntityFramework.AbpDbContext.RegisterToChanges() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\AbpDbContext.cs:line 126
   at Abp.EntityFramework.AbpDbContext.InitializeDbContext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\AbpDbContext.cs:line 121
   at Abp.EntityFramework.AbpDbContext..ctor(String nameOrConnectionString) in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\AbpDbContext.cs:line 70
   at Abp.Zero.EntityFramework.AbpZeroCommonDbContext`2..ctor(String nameOrConnectionString) in D:\Halil\GitHub\module-zero\src\Abp.Zero.EntityFramework\Zero\EntityFramework\AbpZeroCommonDbContext.cs:line 123
   at Abp.Zero.EntityFramework.AbpZeroDbContext`3..ctor(String nameOrConnectionString) in D:\Halil\GitHub\module-zero\src\Abp.Zero.EntityFramework\Zero\EntityFramework\AbpZeroDbContext.cs:line 72
   at Joshi.IP.EntityFramework.IpDbContext..ctor(String nameOrConnectionString) in D:\Freelance Work\Nipun-SPA\VersionUpgrade\Version-1.10.1\Island\Joshi.IP.EntityFramework\EntityFramework\IpDbContext.cs:line 130
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeConstructorInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.FastCreateInstance(Type implType, Object[] arguments, ConstructorCandidate constructor)
   at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType)
   --- End of inner exception stack trace ---

@Sampath-Lokuge
Copy link

Local sql server is working fine.No problem there.I have tested it with the older ABP version and no problem.The problem here is with the latest version. Do you have any clue ?

@hikalkan
Copy link
Author

Are you sure that the connection string is true. Can you share your both DbContextes, at least their constructors

@hikalkan
Copy link
Author

As you see in the stack trace, it's trying to create a new database. Somehow your connection string may have a problem.

@Sampath-Lokuge
Copy link

Connection string is working fine.No problem there.

IpDbContext.cs

 public class IpDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        /* Define an IDbSet for each entity of the application */
        public virtual IDbSet<Property> Properties { get; set; }
        public virtual IDbSet<Investor> Investors { get; set; }

        /* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
         * But it may cause problems when working Migrate.exe of EF. ABP works either way.         * 
         */
        public IpDbContext() : base("Default")
        {

        }

        /* This constructor is used by ABP to pass connection string defined in IPDataModule.PreInitialize.
         * Notice that, actually you will not directly create an instance of IpDbContext since ABP automatically handles it.
         */
        public IpDbContext(string nameOrConnectionString)
            : base(nameOrConnectionString)
        {

        }

        /* This constructor is used in tests to pass a fake/mock connection.
         */
        public IpDbContext(DbConnection dbConnection)
            : base(dbConnection, true)
        {

        }

IpLegacyDbContext.cs

 [AutoRepositoryTypes(typeof(ILegacyRepository<>), typeof(ILegacyRepository<,>), typeof(IpLegacyRepositoryBase<>), typeof(IpLegacyRepositoryBase<,>))]
    public class IpLegacyDbContext : AbpZeroDbContext<Tenant, Role, User>
    {
        public IpLegacyDbContext() : base("Legacy")
        {
        }

        public virtual DbSet<Agent> Agents { get; set; }
        public virtual DbSet<TitleAgent> TitleAgents { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<BuyerInformation>()
                .Property(e => e.Buyerpricerangelow)
                .HasPrecision(19, 4);

            modelBuilder.Entity<BuyerInformation>()
                .Property(e => e.Buyerpricerangehigh)
                .HasPrecision(19, 4);
    }

@hikalkan
Copy link
Author

Is there a connection string named "Legacy" in the web.config? As I remember, they were same databases, why did you define 2 connection strings?

@Sampath-Lokuge
Copy link

I have set the connection string as you mentioned on the forum post and now it's working.I can logged in.But on the first screen it gives below error.Can you tell me why ?

ERROR 2016-05-26 02:05:33,158 [6    ] lers.Filters.AbpExceptionFilterAttribute - Non-static method requires a target.
System.Reflection.TargetException: Non-static method requires a target.
   at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
   at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
   at System.Data.Entity.Core.Objects.ELinq.QueryParameterExpression.TryGetFieldOrPropertyValue(MemberExpression me, Object instance, Object& memberValue)
   at System.Data.Entity.Core.Objects.ELinq.QueryParameterExpression.TryEvaluatePath(Expression expression, ConstantExpression& constantExpression)
   at System.Data.Entity.Core.Objects.ELinq.QueryParameterExpression.EvaluateParameter(Object[] arguments)
   at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassc.<GetResultsAsync>b__a()
   at System.Data.Entity.Core.Objects.ObjectContext.<ExecuteInTransactionAsync>d__3d`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<ExecuteAsyncImplementation>d__9`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult()
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<GetResultsAsync>d__e.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter`1.GetResult()
   at System.Data.Entity.Internal.LazyAsyncEnumerator`1.<FirstMoveNextAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.<ForEachAsync>d__5`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Joshi.IP.Authorization.Users.UserLinkAppService.<GetRecentlyUsedLinkedUsers>d__7.MoveNext() in D:\Freelance Work\Nipun-SPA\VersionUpgrade\Version-1.10.1\Island\Joshi.IP.Application\Authorization\Users\UserLinkAppService.cs:line 80
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinallyAndGetResult>d__5`1.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 120
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()
DEBUG 2016-05-26 02:05:34,326 [13   ] Abp.Web.SignalR.Hubs.AbpCommonHub        - A client is connected: {"ConnectionId":"d4a7b8bb-728a-463b-942c-ef7cfc2c4224","IpAddress":"::1","TenantId":2,"UserId":3,"ConnectTime":"2016-05-25T20:35:34.3168003Z","Properties":{}}
DEBUG 2016-05-26 02:05:34,580 [14   ] Abp.Web.SignalR.Hubs.AbpCommonHub        - A client is registered: d4a7b8bb-728a-463b-942c-ef7cfc2c4224

@hikalkan
Copy link
Author

Maybe your that code is a bit old. Can you share UserLinkAppService's CreateLinkedUsersQuery method?

@Sampath-Lokuge
Copy link

Here it is.I have manually merged all the code changes according to the latest version.Did I miss something here ?

 private async Task<IQueryable<LinkedUserDto>> CreateLinkedUsersQuery(string sorting)
        {
            var currentUserIdentifier = AbpSession.ToUserIdentifier();
            var currentUserAccount = await _userLinkManager.GetUserAccountAsync(AbpSession.ToUserIdentifier());

            return (from userAccount in _userAccountRepository.GetAll()
                    join tenant in _tenantRepository.GetAll() on userAccount.TenantId equals tenant.Id into tenantJoined
                    from tenant in tenantJoined.DefaultIfEmpty()
                    where
                        (userAccount.TenantId != currentUserIdentifier.TenantId ||
                        userAccount.UserId != currentUserIdentifier.UserId) &&
                        userAccount.UserLinkId.HasValue &&
                        userAccount.UserLinkId == currentUserAccount.UserLinkId
                    select new LinkedUserDto
                    {
                        Id = userAccount.UserId,
                        TenantId = userAccount.TenantId,
                        TenancyName = tenant == null ? "." : tenant.TenancyName,
                        Username = userAccount.UserName,
                        LastLoginTime = userAccount.LastLoginTime
                    }).OrderBy(sorting);
        }

@hikalkan
Copy link
Author

I will want help from my partner to check this. For now, can you change GetRecentlyUsedLinkedUsers method to just return an empty list to see if there are any other problems.

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented May 25, 2016

I have done this.But still the same error.

 recentlyUsedlinkedUsers.Clear();
 return new ListResultOutput<LinkedUserDto>(recentlyUsedlinkedUsers);

@Sampath-Lokuge
Copy link

Sampath-Lokuge commented May 25, 2016

It's coming on this line : Before the Clear() method.

var recentlyUsedlinkedUsers = await query.Skip(0).Take(3).ToListAsync();

@Sampath-Lokuge
Copy link

More info about the issue.Please see that.

Alt Text

@Sampath-Lokuge
Copy link

Hi,
Shall I put this issue on the Main repo or is this place enough ?

@hikalkan
Copy link
Author

@mengvisal
Copy link

Hi! I also have the problem of "Found more than one concrete type for given dbcontext type" after I upgrade from 0.8.2.0 to 0.9.3.0. Actually, I use DD design and i have many bounded contexts based on modules i have. Those bounded contexts uses only one single database or one connection string. For 0.8.2.0 version, I can do it without any problems and no need to define a custom repository since different bounded contexts contain different entities mapping and ASP.NET Zero design is smart enough to use the right bounded context. Here, i would like to confirm, for version 0.9.3.0, do i need to define each custom repository for each bounded context i have or is there anyway I can still enjoy using one repository for all bounded contexts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment