优化 FreeSql.Repository 使用方法

This commit is contained in:
28810
2019-02-28 20:38:26 +08:00
parent f034d4194d
commit 8e4d3c03a5
9 changed files with 74 additions and 13 deletions

View File

@ -9,8 +9,55 @@ using Xunit;
namespace FreeSql.Tests.Sqlite {
public class SqliteCodeFirstTest {
class Topic {
public Guid Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; }
}
[Table(Name = "xxxtb.Comment")]
class Comment {
public Guid Id { get; set; }
public Guid TopicId { get; set; }
public Topic Topic { get; set; }
public string Nickname { get; set; }
public string Content { get; set; }
public DateTime CreateTime { get; set; }
}
[Fact]
public void AddField() {
//<2F><>һ<EFBFBD><D2BB> FreeSql.Repository <20><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>dotnet add package FreeSql.Repository
var topicRepository = g.sqlite.GetGuidRepository<Topic>();
var commentRepository = g.sqlite.GetGuidRepository<Comment>();
//<2F><><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var topicId = FreeUtil.NewMongodbId();
topicRepository.Insert(new Topic {
Id = FreeUtil.NewMongodbId(),
Title = "<22><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>1",
Content = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1",
CreateTime = DateTime.Now
});
//<2F><><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
var comments = Enumerable.Range(0, 10).Select(a => new Comment {
Id = FreeUtil.NewMongodbId(),
TopicId = topicId,
Nickname = $"<22>dz<EFBFBD>{a}",
Content = $"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{a}",
CreateTime = DateTime.Now
});
var affrows = commentRepository.Insert(comments);
var find = commentRepository.Select.Where(a => a.Topic.Title == "<22><><EFBFBD>±<EFBFBD><C2B1><EFBFBD>1").ToList();
var sql = g.sqlite.CodeFirst.GetComparisonDDLStatements<TopicAddField>();
var id = g.sqlite.Insert<TopicAddField>().AppendData(new TopicAddField { }).ExecuteIdentity();