- 修复 导航属性配置和Aop冲突的 bug;

This commit is contained in:
28810 2019-09-01 11:12:52 +08:00
parent 56cd333f6f
commit de6e99c710
2 changed files with 34 additions and 2 deletions

View File

@ -385,9 +385,41 @@ namespace FreeSql.Tests
} }
[Table(Name = "bz_web_post")]
public class Post
{
public int Id { get; set; }
public int AuthorId { get; set; }
[Navigate("AuthorId")]
public AuthorTest Author { get; set; }
}
[Table(Name = "bz_web_authortest")]
public class AuthorTest
{
public int Id { get; set; }
public string Name { get; set; }
[Navigate("AuthorId")]
public List<Post> Post { get; set; }
}
[Fact] [Fact]
public void Test1() public void Test1()
{ {
IFreeSql fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.PostgreSQL, "Host=192.168.164.10;Port=5432;Username=postgres;Password=123456;Database=tedb;Pooling=true;Maximum Pool Size=7")
.UseEntityPropertyNameConvert(Internal.StringConvertType.PascalCaseToUnderscoreWithLower)
.UseNoneCommandParameter(true)
.UseAutoSyncStructure(true) //自动同步实体结构到数据库
.UseMonitorCommand(a => Trace.WriteLine(a.CommandText))
.Build();
var data = fsql.Select<Post>().ToList(r => new
{
Id = r.Id,
Name = r.AuthorId.ToString(),
AuthorName = r.Author.Name,
});
//g.mysql.Aop.AuditValue += (s, e) => //g.mysql.Aop.AuditValue += (s, e) =>
//{ //{
// if (e.Column.CsType == typeof(long) // if (e.Column.CsType == typeof(long)

View File

@ -75,8 +75,7 @@ namespace FreeSql.Internal
var setMethod = trytb.Type.GetMethod($"set_{p.Name}"); var setMethod = trytb.Type.GetMethod($"set_{p.Name}");
var colattr = common.GetEntityColumnAttribute(entity, p); var colattr = common.GetEntityColumnAttribute(entity, p);
var tp = common.CodeFirst.GetDbInfo(colattr?.MapType ?? p.PropertyType); var tp = common.CodeFirst.GetDbInfo(colattr?.MapType ?? p.PropertyType);
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤 if (tp == null && colattr?.IsIgnore != true)
if (tp == null && colattr == null)
{ {
if (common.CodeFirst.IsLazyLoading) if (common.CodeFirst.IsLazyLoading)
{ {
@ -88,6 +87,7 @@ namespace FreeSql.Internal
propsNavObjs.Add(p); propsNavObjs.Add(p);
continue; continue;
} }
if (tp == null && colattr != null) colattr.IsIgnore = true; //无法匹配的属性,认定是导航属性,且自动过滤
if (colattr == null) if (colattr == null)
colattr = new ColumnAttribute colattr = new ColumnAttribute
{ {