static void Main(string[] args) { string connectionString = "Data Source = (local);Initial Catalog = CleverDb;Integrated Security = True;MultipleActiveResultSets = True"; CleverDbContext db = new CleverDbContext(connectionString); var obj = new { name = "Насос", parentId = 95, attributes = new { марка = "Bosh", мощность = 95.3, ДатаУстановки = DateTime.Now } }; string stringified = Json.Encode(obj); var clever = CleverObjectService.GetCleverObjectFromJson(stringified); //insert operation CleverObject inserted = db.Insert(clever); Console.WriteLine(inserted.Id); //get operation CleverObject found = db.FindById(inserted.Id); //get subtree operation string json = db.GetSubTreeForTheNode(166); Console.WriteLine("done"); Console.ReadKey(); }
public HttpResponseMessage Get(int id) { string connectionString = ConfigurationManager.ConnectionStrings["defaultConnection"].ConnectionString; CleverDbContext db = new CleverDbContext(connectionString); try { var result = db.FindById(id); return(new HttpResponseMessage() { Content = new StringContent(result == null ? "{}" : result.ToString(), Encoding.UTF8, "application/json") }); } catch (Exception exp) { return(Request.CreateResponse <dynamic>(HttpStatusCode.InternalServerError, new { Exception = exp.GetType().Name.ToString(), Message = exp.Message })); } }