当前位置: 首页>>代码示例>>C#>>正文


C# DataContext.Table方法代码示例

本文整理汇总了C#中DataContext.Table方法的典型用法代码示例。如果您正苦于以下问题:C# DataContext.Table方法的具体用法?C# DataContext.Table怎么用?C# DataContext.Table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataContext的用法示例。


在下文中一共展示了DataContext.Table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveUser

        /// <summary>
        /// Metoda zapisująca informacje o użytkowniku
        /// </summary>
        /// <param name="email"></param>
        /// <param name="result"></param>
        /// <returns></returns>
        public bool SaveUser(string email, Users result)
        {
            try
            {
                using (var context = new DataContext())
                {
                    var user = context.Table<Users>().NewQuery().FirstOrDefault(x => x.Email == email);
                    if (user != null)
                    {
                        user.Name = result.Name;
                        user.Surname = result.Surname;
                        if (!string.IsNullOrEmpty(result.Password))
                        {
                            user.Password = result.Password;
                        }

                        context.Table<Users>().Update(user);
                        context.SaveChanges();

                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                // ojojojoj
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:36,代码来源:AccountService.cs

示例2: AddCity

        public bool AddCity(string email, string city, int quantity)
        {
            var userId = this.GetUserId(email);
            try
            {
                using (var context = new DataContext())
                {
                    var weatherElement = context.Table<Mashup.Data.Model.Weather>().NewRow();
                    weatherElement.ID_user = userId;
                    weatherElement.City = city;
                    weatherElement.Quantity = quantity;

                    context.Table<Mashup.Data.Model.Weather>().Insert(weatherElement);
                    context.SaveChanges();

                    return true;
                }
            }
            catch (Exception)
            {
                //ojojojo
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:25,代码来源:WeatherService.cs

示例3: GetBreakerOperations

        public IEnumerable<BreakerOperation> GetBreakerOperations(EventJSON json)
        {
            using (DataContext dataContext = new DataContext("systemSettings"))
            {
                DateTime startTime = (json != null ? (json.StartDate ?? DateTime.Parse("01/01/01")) : DateTime.Parse("01/01/01"));
                DateTime endTime = (json != null ? (json.EndDate ?? DateTime.Now) : DateTime.Now);

                IEnumerable<DataRow> table = Enumerable.Empty<DataRow>();
                try
                {
                    if (json == null || (json.EventIDList == null && json.MeterAssetKeyList == null && json.LineIDList == null && json.LineAssetKeyList == null && json.MeterIDList == null))
                    {
                        table = dataContext.Connection.RetrieveData("Select * FROM BreakerOperation WHERE TripCoilEnergized >= {0} AND TripCoilEnergized <= {1}", startTime, endTime).Select();
                        return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).ToList();

                    }

                    if (json.MeterIDList != null)
                    {
                        object[] ids = json.MeterIDList.Split(',').Select(int.Parse).Cast<object>().ToArray();
                        string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}"));
                        table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN ({param}))", ids).Select().Concat(table);
                    }
                    if (json.MeterAssetKeyList != null)
                    {
                        object[] ids = json.MeterAssetKeyList.Split(',').Cast<object>().ToArray();
                        string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}"));
                        table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE  TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE MeterID IN (SELECT ID FROM Meter WHERE AssetKey IN ({param})))", ids).Select().Concat(table);
                    }
                    if (json.LineIDList != null)
                    {
                        object[] ids = json.LineIDList.Split(',').Select(int.Parse).Cast<object>().ToArray();
                        string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}"));
                        table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE  TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND  EventID IN (Select ID FROM Event WHERE LineID IN ({param}))", ids).Select().Concat(table);
                    }
                    if (json.LineAssetKeyList != null)
                    {
                        object[] ids = json.LineAssetKeyList.Split(',').Cast<object>().ToArray();
                        string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}"));
                        table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE  TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN (Select ID FROM Event WHERE LineID IN (SELECT ID FROM Line WHERE AssetKey IN ({param})))", ids).Select().Concat(table);
                    }
                    if (json.EventIDList != null)
                    {
                        object[] ids = json.EventIDList.Split(',').Select(int.Parse).Cast<object>().ToArray();
                        string param = string.Join(",", ids.Select((id, index) => $"{{{index}}}"));
                        table = dataContext.Connection.RetrieveData($"Select * FROM BreakerOperation WHERE  TripCoilEnergized >= '{startTime}' AND TripCoilEnergized <= '{endTime}' AND EventID IN ({param})", ids).Select().Concat(table);

                    }

                    return table.Select(row => dataContext.Table<BreakerOperation>().LoadRecord(row)).DistinctBy(evt => evt.ID).ToList();
                }
                catch (Exception)
                {

                    return null;
                }
            }
        }
开发者ID:GridProtectionAlliance,项目名称:openXDA,代码行数:58,代码来源:JSONApiController.cs

示例4: GetUserId

 /// <summary>
 /// Metoda pobierająca id użytkownika na podstawie jego maila
 /// </summary>
 /// <param name="email"></param>
 /// <returns></returns>
 public int GetUserId(string email)
 {
     using (var context = new DataContext())
     {
         return context.Table<Users>().NewQuery().Where(x => x.Email == email).Select(x => x.ID).FirstOrDefault();
     }
 }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:12,代码来源:AccountService.cs

示例5: AddFeed

        /// <summary>
        /// Metoda dodająca nowy feed
        /// </summary>
        /// <param name="email"></param>
        /// <param name="feedUrl"></param>
        /// <returns></returns>
        public bool AddFeed(string email, string feedUrl)
        {
            var userId = this.GetUserId(email);
            try
            {
                using (var context = new DataContext())
                {
                    var feedElement = context.Table<RSS>().NewRow();
                    feedElement.ID_user = userId;
                    feedElement.RSS_URL = feedUrl;

                    context.Table<RSS>().Insert(feedElement);
                    context.SaveChanges();

                    return true;
                }
            }
            catch (Exception)
            {
                //ojojojo
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:30,代码来源:RSSService.cs

示例6: LocalWeather

        public List<LocalWeather> LocalWeather(string userMail)
        {
            try
            {
                using (var context = new DataContext())
                {
                    var user = context.Table<Users>().NewQuery().SingleOrDefault(x => x.Email == userMail);

                    if (user == null)
                    {
                        return new List<LocalWeather>();
                    }

                    var weathers = context.Table<Data.Model.Weather>().NewQuery().Where(x => x.ID_user == user.ID).ToList();

                    return weathers.Select(x => provider.LocalWeather(x.City, x.Quantity)).ToList();
                }
            }
            catch (Exception)
            {
                //ojojojo
                return null;
            }
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:24,代码来源:WeatherService.cs

示例7: GetUserInfo

        public Users GetUserInfo(string email)
        {
            try
            {
                using (var context = new DataContext())
                {
                    var user = context.Table<Users>().NewQuery().Include(x => x.Weather).Include(x => x.RSS).FirstOrDefault(x => x.Email == email);
                    return user;
                }
            }
            catch (Exception ex)
            {
                // ojojojoj
            }

            return null;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:17,代码来源:AccountService.cs

示例8: ValidateUser

        public bool ValidateUser(string email, string password)
        {
            try
            {
                using (var context = new DataContext())
                {
                    return context.Table<Users>().NewQuery().Any(x => x.Email == email && x.Password == password);
                }
            }
            catch (Exception ex)
            {
                // ojojojoj
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:16,代码来源:AccountService.cs

示例9: GetChannelsByMeter

        public IEnumerable<Channel> GetChannelsByMeter(ConfigJSON json)
        {
            using (DataContext dataContext = new DataContext("systemSettings"))
            {
                string assetKey = (json != null ? (json.AssetKey ?? "%") : "%");
                int id = (json != null ? (json.ID == null ? -1 : int.Parse(json.ID)) : -1);
                string name = (json != null ? (json.Name ?? "%") : "%");

                DataTable table = dataContext.Connection.RetrieveData("Select * FROM Channel WHERE MeterID IN (Select ID FROM Meter WHERE AssetKey LIKE {0} AND " + (id != -1 ? "ID LIKE {1} AND " : "") + "NAME LIKE {2})", assetKey, id, name);
                return table.Select().Select(row => dataContext.Table<Channel>().LoadRecord(row)).ToList();
            }
        }
开发者ID:GridProtectionAlliance,项目名称:openXDA,代码行数:12,代码来源:JSONApiController.cs

示例10: GetLines

        public IEnumerable<Line> GetLines(ConfigJSON json)
        {
            using (DataContext dataContext = new DataContext("systemSettings"))
            {
                string assetKey = (json != null ? (json.AssetKey ?? "%") : "%");
                int id = (json != null ? (json.ID == null ? -1 : int.Parse(json.ID)) : -1);

                DataTable table = dataContext.Connection.RetrieveData("Select * FROM Line WHERE AssetKey LIKE {0} " + (id != -1 ? "AND ID LIKE {1}" : "") , assetKey, id);
                return table.Select().Select(row => dataContext.Table<Line>().LoadRecord(row)).ToList();
            }
        }
开发者ID:GridProtectionAlliance,项目名称:openXDA,代码行数:11,代码来源:JSONApiController.cs

示例11: GetEventWaveformData

 public IEnumerable<EventData> GetEventWaveformData(EventDataJSON json)
 {
     if(json != null && json.EventID != null)
     {
         try {
             int eventID = int.Parse(json.EventID);
             using (DataContext dataContext = new DataContext("systemSettings"))
             {
                 DataTable table = dataContext.Connection.RetrieveData("Select * FROM GetEventData({0}) as GottenEventData JOIN Series ON GottenEventData.SeriesID = Series.ID JOIN Channel ON Series.ChannelID = Channel.ID WHERE Characteristic = 'Instantaneous'", eventID);
                 return table.Select().Select(row => dataContext.Table<EventData>().LoadRecord(row)).ToList();
             }
         }
         catch(Exception ex)
         {
             return null;
         }
     }
     else
         return null;
 }
开发者ID:GridProtectionAlliance,项目名称:openXDA,代码行数:20,代码来源:JSONApiController.cs

示例12: GetAllRssFeeds

        /// <summary>
        /// Metoda pobierająca wszystkie feedy
        /// </summary>
        /// <param name="userName">Nazwa zalogowanego uzytkownika</param>
        /// <param name="numberPerFeed">ilość per feed</param>
        /// <returns></returns>
        public List<RSSModel> GetAllRssFeeds(string userName, int? numberPerFeed = null)
        {
            var userId = this.GetUserId(userName);
            var result = new List<RSSModel>();
            try
            {
                using (var context = new DataContext())
                {
                    var feedUrls =
                        context.Table<RSS>().NewQuery().Where(x => x.ID_user == userId).Select(x => x.RSS_URL).ToList();

                    foreach (var url in feedUrls)
                    {
                        var subResult = new RSSModel();

                        XmlReader rssXml;
                        try
                        {
                            rssXml = XmlReader.Create(url);
                        }
                        catch (Exception)
                        {
                            break;
                        }
                        var rss = SyndicationFeed.Load(rssXml);
                        if (rss != null)
                        {
                            subResult.RSSName = rss.Title.Text;
                            subResult.RSSDescription = rss.Description.Text;

                            if (numberPerFeed != null)
                            {
                                rss.Items = rss.Items.OrderBy(x => x.PublishDate.DateTime).Take((int)numberPerFeed).ToList();
                            }

                            foreach (var item in rss.Items)
                            {
                                var rssItemSubResult = new RSSItemModel
                                                           {
                                                               Title = item.Title.Text,
                                                               PublishDate = item.PublishDate.DateTime,
                                                               Content = item.Summary.Text
                                                           };

                                var uri = item.Links.Select(x => x.Uri).FirstOrDefault();
                                if (uri != null)
                                {
                                    rssItemSubResult.Url = uri.AbsoluteUri;
                                }

                                subResult.RssItems.Add(rssItemSubResult);
                            }
                        }

                        result.Add(subResult);
                    }

                    return result;
                }
            }
            catch (Exception)
            {
                // ojojojoj
            }

            return null;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:73,代码来源:RSSService.cs

示例13: RemoveFeed

        /// <summary>
        /// Metoda usuwająca feed
        /// </summary>
        /// <param name="name"></param>
        /// <param name="feedId"></param>
        /// <returns></returns>
        public bool RemoveFeed(string name, int feedId)
        {
            var userId = this.GetUserId(name);
            try
            {
                using (var context = new DataContext())
                {
                    var feedElement =
                        context.Table<RSS>().NewQuery().FirstOrDefault(x => x.ID_user == userId && x.ID == feedId);
                    if (feedElement != null)
                    {
                        context.Table<RSS>().Delete(feedElement);
                        context.SaveChanges();

                        return true;
                    }
                }
            }
            catch (Exception)
            {
                //ojojojo
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:31,代码来源:RSSService.cs

示例14: GetHeaders

        private string GetHeaders(DataContext dataContext, IEnumerable<int> pointIDs)
        {
            object[] parameters = pointIDs.Cast<object>().ToArray();
            string parameterizedQueryString = $"PointID IN ({string.Join(",", parameters.Select((parameter, index) => $"{{{index}}}"))})";
            RecordRestriction pointIDRestriction = new RecordRestriction(parameterizedQueryString, parameters);

            return "\"Timestamp\"," + string.Join(",", dataContext.Table<Measurement>().
                QueryRecords(restriction: pointIDRestriction).
                Select(measurement => $"\"[{measurement.PointID}] {measurement.PointTag}\""));
        }
开发者ID:GridProtectionAlliance,项目名称:openHistorian,代码行数:10,代码来源:ExportDataHandler.ashx.cs

示例15: RemoveCity

        public bool RemoveCity(string email, int cityId)
        {
            var userId = this.GetUserId(email);
            try
            {
                using (var context = new DataContext())
                {
                    var weatherElement =
                        context.Table<Data.Model.Weather>().NewQuery().FirstOrDefault(x => x.ID_user == userId && x.ID == cityId);
                    if (weatherElement != null)
                    {
                        context.Table<Data.Model.Weather>().Delete(weatherElement);
                        context.SaveChanges();

                        return true;
                    }
                }
            }
            catch (Exception)
            {
                //ojojojo
            }

            return false;
        }
开发者ID:pmatwiejuk,项目名称:Mashup,代码行数:25,代码来源:WeatherService.cs


注:本文中的DataContext.Table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。