Get TFS Query GUID - tfs

I am using some existing code in a project where some code is querying using a GUID to get list of WorkItems from a query ( as list of blocking bugs etc.) using a query name and GUID.
var items = project.Store.GetQueryDefinition(queryGUID);
Question : for a given TFS query how can I get its GUID ?

Related

Why does Microsoft Graph Delta Query not return ModifiedBy property?

My usecase requires to fetch ModifiedBy attribute along with other metadata for a list of file system objects from my SharePoint drive.
The problem is that it's missing from the default response, and even if I add it under $select property, it doesn't give me ModifiedBy attribute.
Any idea why? CreatedBy is present though.

How to limit the amount of data from an OData request?

I have a Users table of 76 users and UserGroups table.
Using MVC, OData, a generic repository and EF, I am trying to optimize data retrieval when filtering based on the user group:
/api/Users?$filter=USERGROUPS/any(usergroup: usergroup/ID eq 'Group1')
On the client side, I get the right number of users - 71 (as OData is filtering based on the result), however I want to limit the number of records being returned form the actual query - ie. I do not want to return all records then filter (not optimal for very large data sets).
My API controller method is as follows:
[Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<USER> Get()
{
var unitOfWork = new ATMS.Repository.UnitOfWork(_dbContext);
var users = unitOfWork.Repository<USER>()
.Query()
.Include(u => u.USERGROUPS)
.Get()
.OrderBy(order => order.USERNAME);
unitOfWork.Save(); // includes Dispose()
return users.AsQueryable();
}
I read in this post that:
Entity framework takes care of building dynamic query based on the
request.
However, using a SQL Server profiler, the query executed is requesting all the records, rather than a filtered query.
Adding a .Take() to the query does not accomplish the desired result, as we also need the actual number of records returned for paging purposes.
I was thinking of using the grabbing some properties through ODataQueryOptions, but that doesn't seem quite right either.
Is my implementation of Unit of Work and Repository incorrect, in relation to what I am trying to accomplish, and if so, how can this be corrected?
Simple - Just set the Page size for the Queryable atrribute [Queryable(PageSize=10)]
http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options#server-paging
If You'd tell the EF where to apply the options, it would work.
Like this :
//[Queryable(AllowedQueryOptions = AllowedQueryOptions.All)]
public IQueryable<USER> Get(ODataQueryOptions<USER> options)
{
var users = options.ApplyTo(_dbContext.Set<USER>()
.Query()
.Include(u => u.USERGROUPS)
.Get()
.OrderBy(order => order.USERNAME));
return users;
}
Your code didn't work, because it tried to apply the options onto the last line "users.AsQueryable()", so what actually happened, is that EF pull the FULL dataset, and then applied the query onto the last line (that being a in memory collection). And that's why You didn't see that "filter" not being passed to the SQL.
The mechanics are such, that EF tries to apply the Query, to the IQueryable collection that it finds in the code (there's still a question how does it find the correct line).

How to retrieve user data from two different tables using entity framework

I want to retrieve data of particular user from two different tables such as "Organizations" and "SystemUsers" in which the company details are stored in "Organizations" & his personal info. is stored in "Systemusers" like emailid,password etc..
But what my requirement is I want to retrieve that particular user organization details as well as personal info like emailid, using entityframework in asp.net mvc. Can anyone suggest me the query to do this.
Table: Organizations
public string CompanyName {get; set;}
Table : Systemusers
public string Email {get; set;}
So, I want to retrieve the user company details as well as personal details from two tables so as to display them in search form.Can anyone suggest me query for this????
going by your description and lack of code im assuming that every user will have 0 or 1 organization.
so 1. you will have to make a one to 0 or 1 relation between user and organization then a simple query on the SystemUser table will retrieve the Users personal info and because now in this table you will have a foreign key (assuming name to be Organization) you can retrieve the organiation info using .Organization property of the retrieved SystemUser

How to query a list in LINQ

I have 2 tables in my database, one for projects members and one for projects
After authenticating the user I have his ID. In my project members table I have the project ID and the user ID.
I can obtain a list of project members for this user using
var pm = db.ProjectMembers.Where(c=> c.UserID=u.UserID) ;
Now my question is how can I get a list of ProjectID from the above list. And then how can I get a list of projects from Project table using the list of ProjectID.
First part of your question:
var projectIDs = db.ProjectMembers.Where(c=> c.UserID=u.UserID).select(pm=>pm.ProjectID) ;
2nd part:
if you are using Entity Framework, you should see a property called (project) for every entity of your ProjectMembers list, you can simply ignore my first part of this answer and go directly with this one
var projectsList = db.ProjectMembers.Where(c=> c.UserID=u.UserID).select(pm=>pm.Project) ;
the property may have a different name, give it a try and let me know what happened.
note: that if the retrieved projects were null, then your Entity framework is working wth Eager loading (Google it).
so in order to let the Entity framework generate the proper SQL syntax to retrieve the projects data, add an Include() to your query as the following:
var projectsList = db.ProjectMembers.Where(c=> c.UserID=u.UserID).Include("Projects").select(pm=>pm.Project) ;

How do I use a stored Procedure to return a single entity in Entity Framework 4?

New to Entity Framework .Using EF4. I have found articles and managed to use stored procedures to return a list of entities.
But cannot see/work out how you return a single entity.
Given that I have a stored procedure "GetCustomerById" that return a single customer How do I map it?
Using the Model Browser I right click on "Function Import" and I have added my StoredProcedure
however whatever I select does not seem to return a "Single Entity"
Am I missing the obvious?
thanks a lot for any link or suggestions
When you do Function Import you need to select the entity your SP returns from the drop down (i.e. Customer). The catch is EF does NOT directly returns Customer object as per your selection but System.Data.Objects.ObjectResult which implements IEnumerable.
To be more specific, here is the generated code for your function:
public ObjectResult<Customer> GetCustomerById(Nullable<global::System.Int32> Id)
That's because EF has no idea if your SP returns a single record or a list of them so it wraps the result inside ObjectResult. You can enumerate through this to get your Customer entity like any other IEnumerable object. For example:
Customer myCustomer = context.GetCustomerById(1).First();

Resources