Hi I am working on application to get some details from Sharepoint lists.
I am able to get the results as shown below:
sample.AddRange(queryResults.GetItemRows().Select(listItemRow => new CalendarEvents
{
ItemId = listItemRow.ItemId,
Title = listItemRow.AttributeValueOrDefault("ows_Title", ""),
StartDate = listItemRow.AttributeValueOrDefault("ows_StartDate", ""),
EndDate = listItemRow.AttributeValueOrDefault("ows_EndDate",""),
Link = listItemRow.StrippedAttributeValueOrDefault("ows_Link", "")
}).OrderBy(listItemRow => listItemRow.StartDate));
Where as I am struck at one point:
- I want to extract the list rows with future events. I mean StartDate should be >= present date. I tried some options but no success. I know I need to use .where at the end of AddRange, but how can I check the condition for the date.
I tried as below but didn't work
}).where(listItemRow => listItemRow.StartDate >= dateTime.now)
Any help would be great...
Thankx
Have you make sure you had your data? Is there any error?
If not, try to use:
}).Where(listItemRow => listItemRow.StartDate.After(DateTime.Now));
Related
I am new to Gorm, and currently have a requirement where I need to delete all records older than two weeks.
Right now I am querying my table like this:
String query = "select a from history a where successful = :successful"
List<History> histories = History.executeQuery(query, null, [max:null, offset:null])
for (History history: histories){
Date date1 = New Date()
Date date2 = New Date(history.date)
use(groovy.time.TimeCategory) {
def duration = date1 - date2
if (duration.days > 14){
// delete here
}
}
}
I am certain there is a better and more efficient way to delete all records older than 14 days using gorm, I was wondering if anyone had any knowledge on how to do this? Thank you!
The GORM documentation recommends a couple of options, how about something like:
def twoWeeksAgo = use(TimeCategory){ new Date() - 2.weeks }
History.where{
date < twoWeeksAgo
}.deleteAll()
I'm trying to return a count of records from a database with today's date, using entity framework. I think my query is ok, if you take a look at the screenshot record 2 is the only item out of the 3 with todays date, which is correct.
How can i return a count. Currently its returning a bool value
Thank you
Dim today = DateTime.Today.Date
Dim todaysBuild = retrieveOrders.[Select](Function(build) build.TimeAndDate >= today).ToList()
EDIT:
Dim todaysBuild = retrieveOrders.Where(Function(build) build.TimeAndDate >= today).ToList()
The variable todaysBuild is a list. You need the count (Integer) of that list so add the .Count at the end of your code.
Dim todaysBuild = retrieveOrders.[WHERE](Function(build) build.TimeAndDate >= today).ToList.Count
How can I create an alert when any team member makes changes to the Stack Rank field (only) of any work item in TFS?
You can add a alter filter in a work item team alter just including Stack Rank changes
Sample:
Update
You can also try to use TFS API to achieve this. Below code shows how to query workitems whether a field (ex. System.AssignedTo field) is changed on a given day. For stank rank, FieldName="Microsoft.VSTS.Common.StackRank"
void Main()
{
const String CollectionAddress = "http://mytfsserver/tfs/MyCollection";
using (var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(CollectionAddress)))
{
var server = tfs.GetService<WorkItemStore>();
var changes =
server.Query("select * from WorkItems where [System.ChangedDate] = #Today")
.Cast<WorkItem>()
.SelectMany(wi =>
wi.Revisions
.Cast<Revision>()
.SelectMany(r =>
r.Fields
.Cast<Field>()
.Where(f => !String.IsNullOrEmpty(f.OriginalValue as String) && f.Value != f.OriginalValue && f.ReferenceName == "System.AssignedTo")
.Select(f => new { wi.Id, f.OriginalValue, f.Value, f.ReferenceName, })))
.Dump();
}
}
More detials about how to programilly query work items, please refer the link from MSDN:Query for Bugs, Tasks, and Other Work Items
I want to fine-tune the results in the controller action with a few parameters coming from client.
I was following this answer.
The problem is the logs variable returns no results even if all the parameters are not there (I expect it to return all the records). It works perfectly fine I do
return View(db.Logs.ToList());
But my implementation of the answer by Darren Kopp doesn't return anything at all. My code:
Category cat;
DateTime startDate;
DateTime endDate;
var logs = from log in db.Logs
select log;
if (Enum.TryParse<Category>(viewModel.Category, out cat))
logs = logs.Where(l => l.LogCategory == cat);
if (DateTime.TryParse(viewModel.StartDate, out startDate))
logs = logs.Where(l => l.TimeStamp >= startDate);
return View(logs.ToList());
I am using VS 2015 & this is MVC 5. What is causing the problem?
One of the search functions to our website returns far too many results for one page to handle, so I am trying to add the paging function as provided by here: https://github.com/TroyGoode/PagedList
The solution builds properly and the page will load as well, however when I try to conduct a search a "NotSupportedException" is thrown on the page's controller/Index() method:
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
Visual Studio 2010 points to the return statement when this exception is thrown. This is only my second day working in ASP MVC so any and all suggestion are welcome. Thank you!
case "name":
//if no comma, do a combined search by last name and by corporate name.
searchString = searchString.ToUpper();
var lastAgents =
db.Agent.OrderBy(s => s.LastName).Where(s => s.LastName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification).Include(a => a.SymetraNumberToAgentId);
//end new code
var corp2Agents =
db.Agent.OrderBy(s => s.CorporateName).Where(s => s.CorporateName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification);
if ((corp2Agents.Count() == 0) & (lastAgents.Count() == 0)) ViewBag.ErrorMessage = "None found in search for Last Names and Companies beginning with " + search1;
else ViewBag.Message = "Results of Last Name and Company Name search. Found " + (corp2Agents.Count() + lastAgents.Count()).ToString();
pageNumber = (page ?? 1);
return View(lastAgents.Union(corp2Agents).ToPagedList(pageNumber, pageSize));
Took forever but I found the answer. Both these statements
var lastAgents =
db.Agent.OrderBy(s => s.LastName).Where(s => s.LastName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification).Include(a => a.SymetraNumberToAgentId);
//end new code
var corp2Agents =
db.Agent.OrderBy(s => s.CorporateName).Where(s => s.CorporateName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification);
contain an OrderBy, however this is necessary in the Union statement as well. The final "return" statement is as follows:
return View((lastAgents.Union(corp2Agents)).OrderBy(s => s.sNumber).ToPagedList(pageNumber, pageSize));
Try adding the .OrderBy(s => s.sNumber) in the controller like this:
var lastAgents =
db.Agent.Where(s => s.LastName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification).Include(a => a.SymetraNumberToAgentId).OrderBy(s => s.sNumber);
//end new code
var corp2Agents =
db.Agent.Where(s => s.CorporateName.ToUpper().StartsWith(searchString)).Include(
a => a.AgentIdentification).OrderBy(s => s.CorporateName);