2016-10-27 1 views
2

하나의 열만 jsonb 유형으로 업데이트하려고합니다. 삽입은 놀라움없이 완벽하게 작동하지만 [ComplextType ('json')] 속성을 사용하여 하나의 필드 만 업데이트 할 수있는 방법을 찾을 수 없습니다. db.UpdateOnly (() => new QuestionPoco() {Answers = requestDto.answers }, 여기서 : q => q.Id.ToString() == question.id.ToString());서비스 유형에서 ormLite를 사용하여 복합 유형 필드 (json)를 업데이트하는 방법

답변

2

이제 this commit에서 지원됩니다. 이제 available on MyGet입니다.

우리 또한 추가 한 대신 [CustomField("json")]으로 사용할 수있는 새로운 입력 된 PgSqlTypes Attributes, 예를 들면 :

db.DropAndCreateTable<Question>(); 

var createTableSql = db.GetLastSql(); 
Assert.That(createTableSql, Does.Contain("\"answers\" json NULL")); 

db.Insert(new Question 
{ 
    Id = 1, 
    Answers = new List<Answer> 
    { 
     new Answer { Id = 1, Text = "Q1 Answer1" } 
    } 
}); 

var question = db.SingleById<Question>(1); 
Assert.That(question.Answers.Count, Is.EqualTo(1)); 
Assert.That(question.Answers[0].Text, Is.EqualTo("Q1 Answer1")); 

db.UpdateOnly(() => new Question { 
     Answers = new List<Answer> { new Answer { Id = 1, Text = "Q1 Answer1 Updated" } } 
    }, 
    @where: q => q.Id == 1); 

question = db.SingleById<Question>(1); 
Assert.That(question.Answers[0].Text, Is.EqualTo("Q1 Answer1 Updated")); 
+0

어떤 아이디어 때를 : 당신은 정상, 예를 들어 같은/업데이트를 삽입 할 수 있습니다

public class Question { public int Id { get; set; } public string Text { get; set; } //equivalent to: [CustomField("json")] [PgSqlJson] public List<Answer> Answers { get; set; } } public class Answer { public int Id { get; set; } public string Text { get; set; } } 

nuget과 .net 코어에서 사용할 수 있습니까? – Roman

+0

@Roman v1.0.25에서 사용할 수 있습니다. 이제 NuGet에 있습니다. – mythz