mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 02:32:50 +08:00
修复使用 virtual 后实体序列化问题 #5
This commit is contained in:
parent
5e0cb1eae1
commit
1c66796038
@ -32,6 +32,47 @@ namespace FreeSql.Tests.Sqlite {
|
|||||||
public List<TestTypeInfo> Types { get; set; }
|
public List<TestTypeInfo> Types { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class Song {
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public DateTime? Create_time { get; set; }
|
||||||
|
public bool? Is_deleted { get; set; }
|
||||||
|
public string Title { get; set; }
|
||||||
|
public string Url { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Tag> Tags { get; set; }
|
||||||
|
}
|
||||||
|
public partial class Song_tag {
|
||||||
|
public int Song_id { get; set; }
|
||||||
|
public virtual Song Song { get; set; }
|
||||||
|
|
||||||
|
public int Tag_id { get; set; }
|
||||||
|
public virtual Tag Tag { get; set; }
|
||||||
|
}
|
||||||
|
public partial class Tag {
|
||||||
|
[Column(IsIdentity = true)]
|
||||||
|
public int Id { get; set; }
|
||||||
|
public int? Parent_id { get; set; }
|
||||||
|
public virtual Tag Parent { get; set; }
|
||||||
|
|
||||||
|
public decimal? Ddd { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Song> Songs { get; set; }
|
||||||
|
public virtual ICollection<Tag> Tags { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Lazy() {
|
||||||
|
var tags = g.sqlite.Select<Tag>().Where(a => a.Parent.Name == "xxx")
|
||||||
|
.LeftJoin(a => a.Parent_id == a.Parent.Id)
|
||||||
|
.ToSql();
|
||||||
|
|
||||||
|
var songs = g.sqlite.Select<Song>().Limit(10).ToList();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToList() {
|
public void ToList() {
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ namespace FreeSql.Internal {
|
|||||||
.AppendLine("using Newtonsoft.Json;")
|
.AppendLine("using Newtonsoft.Json;")
|
||||||
.AppendLine()
|
.AppendLine()
|
||||||
.Append("public class ").Append(trytbTypeLazyName).Append(" : ").Append(trytbTypeName).AppendLine(" {")
|
.Append("public class ").Append(trytbTypeLazyName).Append(" : ").Append(trytbTypeName).AppendLine(" {")
|
||||||
.AppendLine(" [JsonIgnore] public IFreeSql __fsql_orm__ { get; set; }\r\n");
|
.AppendLine(" [JsonIgnore] private IFreeSql __fsql_orm__ { get; set; }\r\n");
|
||||||
|
|
||||||
foreach (var vp in propsLazy) {
|
foreach (var vp in propsLazy) {
|
||||||
var propTypeName = vp.Item1.PropertyType.IsGenericType ?
|
var propTypeName = vp.Item1.PropertyType.IsGenericType ?
|
||||||
@ -430,7 +430,7 @@ namespace FreeSql.Internal {
|
|||||||
var assemly = Generator.TemplateEngin._compiler.Value.CompileCode(cscode.ToString());
|
var assemly = Generator.TemplateEngin._compiler.Value.CompileCode(cscode.ToString());
|
||||||
var type = assemly.DefinedTypes.Where(a => a.FullName.EndsWith(trytbTypeLazyName)).FirstOrDefault();
|
var type = assemly.DefinedTypes.Where(a => a.FullName.EndsWith(trytbTypeLazyName)).FirstOrDefault();
|
||||||
trytb.TypeLazy = type;
|
trytb.TypeLazy = type;
|
||||||
trytb.TypeLazySetOrm = type.GetProperty("__fsql_orm__").GetSetMethod();
|
trytb.TypeLazySetOrm = type.GetProperty("__fsql_orm__", BindingFlags.Instance | BindingFlags.NonPublic).GetSetMethod(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
Loading…
x
Reference in New Issue
Block a user