コード例 #1
0
        public IActionResult Get(int id)
        {
            var entity = Context.Set <T>().Find(id);

            if (entity == null)
            {
                return(NotFound());
            }

            return(Json(entity));
        }
コード例 #2
0
        private int Read <T>(StreamReader streamReader) where T : class, IEntity, new()
        {
            var count = 0;
            var rep   = _context.Set <T>();

            using (var js = new JsonTextReader(streamReader))
            {
                js.SupportMultipleContent = true;

                while (js.Read() && js.TokenType != JsonToken.StartArray)
                {
                    ;
                }

                var serializer = new JsonSerializer();
                while (js.Read() && js.TokenType != JsonToken.EndArray)
                {
                    var value = serializer.Deserialize <T>(js);

                    rep.Add(value);

                    count++;
                }
            }
            return(count);
        }