mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
修复 IsIgnore 过滤字段后,查询的错误;
This commit is contained in:
parent
b33536e4df
commit
8d266a556e
@ -1,5 +1,6 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using FreeSql.Tests.DataContext.SqlServer;
|
using FreeSql.Tests.DataContext.SqlServer;
|
||||||
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.DataAnnotations {
|
namespace FreeSql.Tests.DataAnnotations {
|
||||||
@ -56,5 +57,22 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
|
|
||||||
public string name { get; set; } = "defaultValue";
|
public string name { get; set; } = "defaultValue";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsIgnore() {
|
||||||
|
var item = new TestIsIgnore { };
|
||||||
|
Assert.Equal(1, g.mysql.Insert<TestIsIgnore>().AppendData(item).ExecuteAffrows());
|
||||||
|
|
||||||
|
var find = g.mysql.Select<TestIsIgnore>().Where(a => a.id == item.id).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestIsIgnore {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
|
||||||
|
[Column(IsIgnore = true)]
|
||||||
|
public bool isignore { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using FreeSql.DataAnnotations;
|
using FreeSql.DataAnnotations;
|
||||||
using FreeSql.Tests.DataContext.SqlServer;
|
using FreeSql.Tests.DataContext.SqlServer;
|
||||||
|
using System;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace FreeSql.Tests.DataAnnotations {
|
namespace FreeSql.Tests.DataAnnotations {
|
||||||
@ -81,6 +82,23 @@ namespace FreeSql.Tests.DataAnnotations {
|
|||||||
|
|
||||||
public string name { get; set; } = "defaultValue";
|
public string name { get; set; } = "defaultValue";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void IsIgnore() {
|
||||||
|
var item = new TestIsIgnore { };
|
||||||
|
Assert.Equal(1, _sqlserverFixture.SqlServer.Insert<TestIsIgnore>().AppendData(item).ExecuteAffrows());
|
||||||
|
|
||||||
|
var find = _sqlserverFixture.SqlServer.Select<TestIsIgnore>().Where(a => a.id == item.id).First();
|
||||||
|
Assert.NotNull(find);
|
||||||
|
Assert.Equal(item.id, find.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestIsIgnore {
|
||||||
|
public Guid id { get; set; }
|
||||||
|
|
||||||
|
[Column(IsIgnore = true)]
|
||||||
|
public bool isignore { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -246,6 +246,8 @@ namespace FreeSql.Tests.MySql {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOne() {
|
public void ToOne() {
|
||||||
|
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||||
|
Assert.Equal(default(DateTime), testnotfind);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSql() {
|
public void ToSql() {
|
||||||
|
@ -156,6 +156,8 @@ namespace FreeSql.Tests.Oracle {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOne() {
|
public void ToOne() {
|
||||||
|
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||||
|
Assert.Equal(default(DateTime), testnotfind);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSql() {
|
public void ToSql() {
|
||||||
|
@ -226,6 +226,8 @@ namespace FreeSql.Tests.PostgreSQL {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOne() {
|
public void ToOne() {
|
||||||
|
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||||
|
Assert.Equal(default(DateTime), testnotfind);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSql() {
|
public void ToSql() {
|
||||||
|
@ -158,6 +158,8 @@ namespace FreeSql.Tests.SqlServer {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOne() {
|
public void ToOne() {
|
||||||
|
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||||
|
Assert.Equal(default(DateTime), testnotfind);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSql() {
|
public void ToSql() {
|
||||||
|
@ -167,6 +167,8 @@ namespace FreeSql.Tests.Sqlite {
|
|||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOne() {
|
public void ToOne() {
|
||||||
|
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||||
|
Assert.Equal(default(DateTime), testnotfind);
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSql() {
|
public void ToSql() {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
<Version>0.5.1.1</Version>
|
<Version>0.5.1.2</Version>
|
||||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
<Authors>YeXiangQin</Authors>
|
<Authors>YeXiangQin</Authors>
|
||||||
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
<Description>FreeSql is the most convenient ORM in dotnet. It supports Mysql, Postgresql, SqlServer, Oracle and Sqlite.</Description>
|
||||||
|
@ -377,6 +377,8 @@ namespace FreeSql.Internal.CommonProvider {
|
|||||||
var index = 0;
|
var index = 0;
|
||||||
var otherindex = 0;
|
var otherindex = 0;
|
||||||
foreach (var prop in props.Values) {
|
foreach (var prop in props.Values) {
|
||||||
|
if (tb.Table.ColumnsByCsIgnore.ContainsKey(prop.Name)) continue;
|
||||||
|
|
||||||
if (tb.Table.ColumnsByCs.TryGetValue(prop.Name, out var col)) { //普通字段
|
if (tb.Table.ColumnsByCs.TryGetValue(prop.Name, out var col)) { //普通字段
|
||||||
if (index > 0) field.Append(", ");
|
if (index > 0) field.Append(", ");
|
||||||
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
var quoteName = _commonUtils.QuoteSqlName(col.Attribute.Name);
|
||||||
|
@ -11,6 +11,7 @@ namespace FreeSql.Internal.Model {
|
|||||||
public Dictionary<string, PropertyInfo> Properties { get; set; } = new Dictionary<string, PropertyInfo>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, PropertyInfo> Properties { get; set; } = new Dictionary<string, PropertyInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public Dictionary<string, ColumnInfo> Columns { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, ColumnInfo> Columns { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
public Dictionary<string, ColumnInfo> ColumnsByCs { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
|
public Dictionary<string, ColumnInfo> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||||
public ColumnInfo[] Primarys { get; set; }
|
public ColumnInfo[] Primarys { get; set; }
|
||||||
public string CsName { get; set; }
|
public string CsName { get; set; }
|
||||||
public string DbName { get; set; }
|
public string DbName { get; set; }
|
||||||
|
@ -70,7 +70,6 @@ namespace FreeSql.Internal {
|
|||||||
IsPrimary = false,
|
IsPrimary = false,
|
||||||
IsIgnore = false
|
IsIgnore = false
|
||||||
};
|
};
|
||||||
if (colattr.IsIgnore) continue;
|
|
||||||
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
||||||
colattr.DbType = colattr.DbType.ToUpper();
|
colattr.DbType = colattr.DbType.ToUpper();
|
||||||
|
|
||||||
@ -104,6 +103,10 @@ namespace FreeSql.Internal {
|
|||||||
CsType = p.PropertyType,
|
CsType = p.PropertyType,
|
||||||
Attribute = colattr
|
Attribute = colattr
|
||||||
};
|
};
|
||||||
|
if (colattr.IsIgnore) {
|
||||||
|
trytb.ColumnsByCsIgnore.Add(p.Name, col);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
trytb.Columns.Add(colattr.Name, col);
|
trytb.Columns.Add(colattr.Name, col);
|
||||||
trytb.ColumnsByCs.Add(p.Name, col);
|
trytb.ColumnsByCs.Add(p.Name, col);
|
||||||
}
|
}
|
||||||
@ -807,6 +810,8 @@ namespace FreeSql.Internal {
|
|||||||
Expression.Assign(readpknullExp, Expression.Constant(false))
|
Expression.Assign(readpknullExp, Expression.Constant(false))
|
||||||
});
|
});
|
||||||
foreach (var ctorParm in ctorParms) {
|
foreach (var ctorParm in ctorParms) {
|
||||||
|
if (typetb.ColumnsByCsIgnore.ContainsKey(ctorParm.Name)) continue;
|
||||||
|
|
||||||
var ispkExp = new List<Expression>();
|
var ispkExp = new List<Expression>();
|
||||||
Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp));
|
Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp));
|
||||||
Expression readExpAssign = null; //加速缓存
|
Expression readExpAssign = null; //加速缓存
|
||||||
@ -823,7 +828,7 @@ namespace FreeSql.Internal {
|
|||||||
|
|
||||||
//判断主键为空,则整个对象不读取
|
//判断主键为空,则整个对象不读取
|
||||||
//blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
|
//blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
|
||||||
if (typetb.ColumnsByCs.TryGetValue(ctorParm.Name, out var trycol) && trycol.Attribute.IsPrimary) {
|
if (typetb.ColumnsByCs.TryGetValue(ctorParm.Name, out var trycol) && trycol.Attribute.IsPrimary == true) {
|
||||||
ispkExp.Add(
|
ispkExp.Add(
|
||||||
Expression.IfThen(
|
Expression.IfThen(
|
||||||
Expression.AndAlso(
|
Expression.AndAlso(
|
||||||
@ -892,6 +897,8 @@ namespace FreeSql.Internal {
|
|||||||
var props = type.GetProperties();//.ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
|
var props = type.GetProperties();//.ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
|
||||||
var propIndex = 0;
|
var propIndex = 0;
|
||||||
foreach (var prop in props) {
|
foreach (var prop in props) {
|
||||||
|
if (typetb.ColumnsByCsIgnore.ContainsKey(prop.Name)) continue;
|
||||||
|
|
||||||
var ispkExp = new List<Expression>();
|
var ispkExp = new List<Expression>();
|
||||||
var propGetSetMethod = prop.GetSetMethod();
|
var propGetSetMethod = prop.GetSetMethod();
|
||||||
Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, tryidxExp));
|
Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, tryidxExp));
|
||||||
@ -909,7 +916,7 @@ namespace FreeSql.Internal {
|
|||||||
|
|
||||||
//判断主键为空,则整个对象不读取
|
//判断主键为空,则整个对象不读取
|
||||||
//blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
|
//blockExp.Add(Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp)));
|
||||||
if (typetb.ColumnsByCs.TryGetValue(prop.Name, out var trycol) && trycol.Attribute.IsPrimary) {
|
if (typetb.ColumnsByCs.TryGetValue(prop.Name, out var trycol) && trycol.Attribute.IsPrimary == true) {
|
||||||
ispkExp.Add(
|
ispkExp.Add(
|
||||||
Expression.IfThen(
|
Expression.IfThen(
|
||||||
Expression.AndAlso(
|
Expression.AndAlso(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user