Skip to content

Commit

Permalink
fix DyRepository SqlParameterCollection paramType problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Apr 2, 2019
1 parent 707d543 commit 877dc40
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<VersionMajor>4</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionPatch>4</VersionPatch>
<VersionPatch>5</VersionPatch>
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
</PropertyGroup>
</Project>
9 changes: 7 additions & 2 deletions src/SmartSql.DyRepository/EmitRepositoryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ private bool IsSimpleParam(Type paramType)
{
return false;
}
if (SqlParameterType.SqlParameterCollection == paramType)
{
return false;
}
if (paramType.IsValueType) { return true; }
if (paramType == typeof(string)) { return true; }
if (paramType.IsGenericParameter) { return true; }

return DataType.Enumerable.IsAssignableFrom(paramType);
}
#region Pre
private string PreScoe(Type interfaceType, string scope = "")
private string PreScope(Type interfaceType, string scope = "")
{
var sqlmapAttr = interfaceType.GetCustomAttribute<SqlMapAttribute>();
if (sqlmapAttr != null && !string.IsNullOrEmpty(sqlmapAttr.Scope))
Expand Down Expand Up @@ -437,7 +442,7 @@ public Type Build(Type interfaceType, SmartSqlConfig smartSqlConfig, string scop
typeBuilder.AddInterfaceImplementation(interfaceType);
var sqlMapperField = typeBuilder.DefineField("sqlMapper", ISqlMapperType.Type, FieldAttributes.Family);
var scopeField = typeBuilder.DefineField("scope", CommonType.String, FieldAttributes.Family);
scope = PreScoe(interfaceType, scope);
scope = PreScope(interfaceType, scope);
EmitBuildCtor(scope, typeBuilder, sqlMapperField, scopeField);
var interfaceMethods = new List<MethodInfo>();

Expand Down
2 changes: 1 addition & 1 deletion src/SmartSql.Test.Unit/Cache/RedisCacheProviderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SmartSql.Test.Unit.Cache
{
public class RedisCacheProviderTest : AbstractXmlConfigBuilderTest
{
[Fact]
//[Fact]
public void QueryByRedisCache()
{
var list = DbSession.Query<AllPrimitive>(new RequestContext
Expand Down
35 changes: 35 additions & 0 deletions src/SmartSql.Test.Unit/DyRepository/UserRepository_Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Text;
using SmartSql.Data;
using SmartSql.Test.Repositories;
using Xunit;

namespace SmartSql.Test.Unit.DyRepository
{
public class UserRepository_Test : DyRepositoryTest
{
private IUserRepository _userRepository;
public UserRepository_Test()
{
var smartSqlBuilder = new SmartSqlBuilder().UseXmlConfig().Build();
_userRepository = RepositoryFactory.CreateInstance(typeof(IUserRepository), smartSqlBuilder.SqlMapper) as IUserRepository;
}


[Fact]
public void SP_QueryUser()
{
SqlParameterCollection dbParameterCollection = new SqlParameterCollection();
dbParameterCollection.Add(new SqlParameter("Total", null, typeof(int))
{
DbType = System.Data.DbType.Int32,
Direction = System.Data.ParameterDirection.Output
});
var list = _userRepository.SP_QueryUser(dbParameterCollection);
Assert.NotNull(list);
dbParameterCollection.TryGetParameterValue("Total", out int total);
Assert.NotEqual(0, total);
}
}
}
8 changes: 4 additions & 4 deletions src/SmartSql.Test.Unit/Maps/AllPrimitive.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<Cache Id="FifoCache" Type="Fifo">
<Property Name="CacheSize" Value="2"/>
</Cache>
<Cache Id="RedisCache" Type="${RedisCacheProvider}">
<!--<Cache Id="RedisCache" Type="${RedisCacheProvider}">
<Property Name="ConnectionString" Value="${Redis}" />
<FlushInterval Seconds="60"/>
</Cache>
</Cache>-->
</Caches>
<MultipleResultMaps>
<MultipleResultMap Id="GetByPage">
Expand Down Expand Up @@ -116,9 +116,9 @@

</Where>
</Statement>
<Statement Id="QueryByRedisCache" Cache="RedisCache">
<!--<Statement Id="QueryByRedisCache" Cache="RedisCache">
SELECT Top 6 T.* From T_AllPrimitive T;
</Statement>
</Statement>-->
<Statement Id="QueryByLruCache" Cache="LruCache">
SELECT Top 6 T.* From T_AllPrimitive T;
</Statement>
Expand Down
6 changes: 6 additions & 0 deletions src/SmartSql.Test/Repositories/IUserRepository.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
using SmartSql.Test.Entities;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using SmartSql.Configuration;
using SmartSql.Data;
using SmartSql.DyRepository.Annotations;

namespace SmartSql.Test.Repositories
{
public interface IUserRepository
{
long Insert(User user);
IEnumerable<User> Query();
[Statement(CommandType = CommandType.StoredProcedure,Sql = "SP_QueryUser")]
IEnumerable<User> SP_QueryUser(SqlParameterCollection sqlParameterCollection);
}
}

0 comments on commit 877dc40

Please sign in to comment.