mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 10:42:52 +08:00
修复 IsIgnore 过滤字段后,查询的错误;
This commit is contained in:
parent
b33536e4df
commit
8d266a556e
@ -1,5 +1,6 @@
|
||||
using FreeSql.DataAnnotations;
|
||||
using FreeSql.Tests.DataContext.SqlServer;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.DataAnnotations {
|
||||
@ -56,5 +57,22 @@ namespace FreeSql.Tests.DataAnnotations {
|
||||
|
||||
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.Tests.DataContext.SqlServer;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace FreeSql.Tests.DataAnnotations {
|
||||
@ -81,6 +82,23 @@ namespace FreeSql.Tests.DataAnnotations {
|
||||
|
||||
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]
|
||||
public void ToOne() {
|
||||
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||
Assert.Equal(default(DateTime), testnotfind);
|
||||
}
|
||||
[Fact]
|
||||
public void ToSql() {
|
||||
|
@ -156,6 +156,8 @@ namespace FreeSql.Tests.Oracle {
|
||||
}
|
||||
[Fact]
|
||||
public void ToOne() {
|
||||
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||
Assert.Equal(default(DateTime), testnotfind);
|
||||
}
|
||||
[Fact]
|
||||
public void ToSql() {
|
||||
|
@ -226,6 +226,8 @@ namespace FreeSql.Tests.PostgreSQL {
|
||||
}
|
||||
[Fact]
|
||||
public void ToOne() {
|
||||
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||
Assert.Equal(default(DateTime), testnotfind);
|
||||
}
|
||||
[Fact]
|
||||
public void ToSql() {
|
||||
|
@ -158,6 +158,8 @@ namespace FreeSql.Tests.SqlServer {
|
||||
}
|
||||
[Fact]
|
||||
public void ToOne() {
|
||||
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||
Assert.Equal(default(DateTime), testnotfind);
|
||||
}
|
||||
[Fact]
|
||||
public void ToSql() {
|
||||
|
@ -167,6 +167,8 @@ namespace FreeSql.Tests.Sqlite {
|
||||
}
|
||||
[Fact]
|
||||
public void ToOne() {
|
||||
var testnotfind = select.Where("1=2").First(a => a.CreateTime);
|
||||
Assert.Equal(default(DateTime), testnotfind);
|
||||
}
|
||||
[Fact]
|
||||
public void ToSql() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>0.5.1.1</Version>
|
||||
<Version>0.5.1.2</Version>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Authors>YeXiangQin</Authors>
|
||||
<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 otherindex = 0;
|
||||
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 (index > 0) field.Append(", ");
|
||||
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, 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> ColumnsByCsIgnore { get; set; } = new Dictionary<string, ColumnInfo>(StringComparer.CurrentCultureIgnoreCase);
|
||||
public ColumnInfo[] Primarys { get; set; }
|
||||
public string CsName { get; set; }
|
||||
public string DbName { get; set; }
|
||||
|
@ -70,7 +70,6 @@ namespace FreeSql.Internal {
|
||||
IsPrimary = false,
|
||||
IsIgnore = false
|
||||
};
|
||||
if (colattr.IsIgnore) continue;
|
||||
if (string.IsNullOrEmpty(colattr.DbType)) colattr.DbType = tp?.dbtypeFull ?? "varchar(255)";
|
||||
colattr.DbType = colattr.DbType.ToUpper();
|
||||
|
||||
@ -104,6 +103,10 @@ namespace FreeSql.Internal {
|
||||
CsType = p.PropertyType,
|
||||
Attribute = colattr
|
||||
};
|
||||
if (colattr.IsIgnore) {
|
||||
trytb.ColumnsByCsIgnore.Add(p.Name, col);
|
||||
continue;
|
||||
}
|
||||
trytb.Columns.Add(colattr.Name, col);
|
||||
trytb.ColumnsByCs.Add(p.Name, col);
|
||||
}
|
||||
@ -807,6 +810,8 @@ namespace FreeSql.Internal {
|
||||
Expression.Assign(readpknullExp, Expression.Constant(false))
|
||||
});
|
||||
foreach (var ctorParm in ctorParms) {
|
||||
if (typetb.ColumnsByCsIgnore.ContainsKey(ctorParm.Name)) continue;
|
||||
|
||||
var ispkExp = new List<Expression>();
|
||||
Expression readVal = Expression.Assign(readpkvalExp, Expression.Call(rowExp, MethodDataReaderGetValue, dataIndexExp));
|
||||
Expression readExpAssign = null; //加速缓存
|
||||
@ -823,7 +828,7 @@ namespace FreeSql.Internal {
|
||||
|
||||
//判断主键为空,则整个对象不读取
|
||||
//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(
|
||||
Expression.IfThen(
|
||||
Expression.AndAlso(
|
||||
@ -892,6 +897,8 @@ namespace FreeSql.Internal {
|
||||
var props = type.GetProperties();//.ToDictionary(a => a.Name, a => a, StringComparer.CurrentCultureIgnoreCase);
|
||||
var propIndex = 0;
|
||||
foreach (var prop in props) {
|
||||
if (typetb.ColumnsByCsIgnore.ContainsKey(prop.Name)) continue;
|
||||
|
||||
var ispkExp = new List<Expression>();
|
||||
var propGetSetMethod = prop.GetSetMethod();
|
||||
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)));
|
||||
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(
|
||||
Expression.IfThen(
|
||||
Expression.AndAlso(
|
||||
|
Loading…
x
Reference in New Issue
Block a user