Skip to content

Commit

Permalink
fix wrong type check
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Qu authored and Victor Qu committed Nov 7, 2024
1 parent 93e1a2c commit 2f4a520
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ProjectCommon.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionSuffix>$(VersionSuffix)</VersionSuffix>
<Version>0.0.2.12</Version>
<Version>0.0.2.13</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Version Condition=" '$(VersionSuffix)' != '' ">$(Version)$(VersionSuffix)</Version>
Expand Down
15 changes: 14 additions & 1 deletion src/SV.Db.Sloth/DbEntityInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,21 @@ public static DbEntityInfo Get()
}).Select(i => new KeyValuePair<string, string>(i.Key, i.Value.Field)).ToArray();
var checkUps = ups.Select(i =>
{
Type t;
var f = fields.First(x => x.Name.Equals(i.Key, StringComparison.OrdinalIgnoreCase));
if (f.DeclaringType.IsValueType && Nullable.GetUnderlyingType(f.DeclaringType) is null)
if (f is PropertyInfo p)
{
t = p.PropertyType;
}
else if (f is FieldInfo field)
{
t = field.FieldType;
}
else
{
return null;
}
if (t.IsValueType && Nullable.GetUnderlyingType(t) is null)
{
return null;
}
Expand Down
38 changes: 38 additions & 0 deletions test/RestfulSample/Controllers/WeatherForecastController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SV.Db.Sloth;
using SV.Db.Sloth.Attributes;
using SV.Db.Sloth.Swagger;
using System.Data;

namespace RestfulSample.Controllers
{
Expand Down Expand Up @@ -79,6 +80,13 @@ public async Task<object> Update([FromBody] Weather[] weather)
{
return await factory.ExecuteUpdateAsync<Weather>(weather);
}

[HttpGet("TEST")]
[DbSwaggerByType(typeof(UserInfo))]
public async Task<object> QueryUserInfo()
{
return await this.QueryByParamsAsync<UserInfo>();
}
}

[Db(StaticInfo.Demo)]
Expand All @@ -105,9 +113,39 @@ public class Weather
""")]
public string? SKU { get; set; }

[Select("a.LastLoginDate"), OrderBy, Where, Column(Name = "LastLoginDate", Type = DbType.Int64), Update]
public long? LastLoginDate { get; set; }

public static object C(object c)
{
return System.Text.Json.JsonSerializer.Serialize(c);
}
}

[Db(StaticInfo.Demo)]
[Table("""
select {Fields}
FROM users a
{where}
""", UpdateTable = "users")]
public class UserInfo
{
[Select("a.Id"), OrderBy, Where, Column(Name = "Id", Type = DbType.Int32), Update(PrimaryKey = true, NotAllowInsert = true)]
public int? Id { get; set; }

[Select("a.DisplayName"), OrderBy, Where, Column(Name = "DisplayName"), Update]
public string? DisplayName { get; set; }

[Select("a.Password"), OrderBy, Where, Column(Name = "Password"), Update]
public string? Password { get; set; }

[Select("a.Email"), OrderBy, Where, Column(Name = "Email"), Update]
public string? Email { get; set; }

[Select("a.LastLoginDate"), OrderBy, Column(Name = "LastLoginDate", Type = DbType.Int64), Update]
public long? LastLoginDate { get; set; }

[Select("a.InDate"), OrderBy, Where, Column(Name = "InDate", Type = DbType.Int64), Update]
public long InDate { get; set; }
}
}

0 comments on commit 2f4a520

Please sign in to comment.