本文整理汇总了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;
}
示例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;
}
示例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;
}
}
}
示例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();
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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}\""));
}
示例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;
}