C# 异常插入列表<;T>;在拉文德
我确实尝试将列表投射到数组中…尽管感觉不太对劲。。那也失败了。。此外,为什么我必须使用C# 异常插入列表<;T>;在拉文德,c#,.net,ravendb,C#,.net,Ravendb,我确实尝试将列表投射到数组中…尽管感觉不太对劲。。那也失败了。。此外,为什么我必须使用ravenjabObject和RavenJArray来dela,而不是Json.net附带的默认值。。我猜在幕后正在进行一些漂亮的工作。发生异常是因为您在调用时试图存储一系列问题:session.store(问题) api希望收到一个实体来持久化,而不是数组或集合 您可能希望使用批处理操作来处理一系列问题的加载:看起来[在RavenDB中存储对象需要什么][1]中给出的答案可能会对您有所帮助。[1]: publ
ravenjabObject
和RavenJArray
来dela,而不是Json.net
附带的默认值。。我猜在幕后正在进行一些漂亮的工作。发生异常是因为您在调用时试图存储一系列问题:session.store(问题)代码>
api希望收到一个实体来持久化,而不是数组或集合
您可能希望使用批处理操作来处理一系列问题的加载:看起来[在RavenDB中存储对象需要什么][1]中给出的答案可能会对您有所帮助。[1]:
public class Question
{
public int Id { get; set; }
public int? Score { get; set; }
public string Title { get; set; }
public List<string> Tags { get; set; }
public Owner Owner { get; set; }
public Uri Link { get; set; }
public bool IsAnswered { get; set; }
}
public class Owner
{
public int? ID { get; set; }
public String Name { get; set; }
public int Reputation { get; set; }
public Uri Link { get; set; }
}
public static dynamic CallStackOverFlow()
{
var client = new RestClient("https://api.stackexchange.com/2.1");
var request = new RestRequest("/search/advanced", Method.GET);
request.RequestFormat = DataFormat.Json;
request.AddParameter("site", "stackoverflow");
request.AddParameter("tagged", "C#");
request.AddParameter("pagesize", "1");
var response = client.Execute(request);
var content = response.Content; // raw content as string
dynamic deserialised = JsonConvert.DeserializeObject(content);
return deserialised;
}
//go call stackoverflow
var d = StackOverflow.CallStackOverFlow();
var questions = new List<Question>();
foreach (var q in d.items)
{
Console.WriteLine(q);
var question = new Question
{
Id = q.question_id,
IsAnswered = q.is_answered,
Link = new Uri(q.link == null ? "" : (string)q.link),
Owner = new Owner
{
ID = q.owner.user_id,
Link = new Uri(q.owner.link == null ? "" : (string)q.owner.link),
Name = q.owner.display_name,
Reputation = q.owner.reputation
},
Tags = (q.tags as JArray).Values().Select(v => v.ToString()).ToList(),
Score = q.score,
Title = q.title
};
questions.Add(question);
}
using (IDocumentStore documentStore = new DocumentStore() { Url = "http://localhost:8080", DefaultDatabase = "StackOverflow" })
{
documentStore.Initialize();
using (IDocumentSession session = documentStore.OpenSession())
{
session.Store(questions);
session.SaveChanges();
}
}
Object serialized to Array. RavenJObject instance expected.