score:1
Accepted answer
//just grab the first item
var item = result.getsplistitems().firstordefault();
//then grab the properties into the existing contractactionentity
contractaction.title = item.getspfieldvalue("title");
contractaction.description = item.getspfieldvalue("description");
contractaction.deliveryorderid = sphelper.getfirstlookupid(item.getspfieldvalue("delivery order"));
contractaction.estimatedvalue = item.getspfieldvalue("estimated value").tonullabledouble();
contractaction.agreementtypeid = sphelper.getfirstlookupid(item.getspfieldvalue("contract type")),
score:0
var item = (from listitem in result.getsplistitems()
from query2outer in result.secondquery().where(x => x.itemedp == it.itemedp).defaultifempty() // this is an outer join
select new action
{
//if the one query didn't return an item then it sets the properties to the default values
example = (query2outer == null ? "default value" : query2outer.example),
title = listitem.getspfieldvalue("title"),
description = listitem.getspfieldvalue("description"),
deliveryorderid = sphelper.getfirstlookupid(listitem.getspfieldvalue("delivery order")),
estimatedvalue = ((listitem.getspfieldvalue("estimated value") as double?) ?? 0),
agreementtypeid = sphelper.getfirstlookupid(listitem.getspfieldvalue("contract type")),
}).firstordefault();
score:0
contractaction targetaction = new contractaction();
var item = (from listitem in result.getsplistitems()
select new contractaction
{
title = listitem.getspfieldvalue("title"),
description = listitem.getspfieldvalue("description"),
deliveryorderid = sphelper.getfirstlookupid(listitem.getspfieldvalue("delivery order")),
estimatedvalue = ((listitem.getspfieldvalue("estimated value") as double?) ?? 0),
agreementtypeid = sphelper.getfirstlookupid(listitem.getspfieldvalue("contract type")),
}).selectfirstinto(targetaction);
score:1
public static myaction tomyaction(this splistitem item)
{
return new myaction
{
title = item.getspfieldvalue("title"),
description = item.getspfieldvalue("description"),
deliveryorderid = sphelper.getfirstlookupid(item.getspfieldvalue("delivery order")),
estimatedvalue = ((item.getspfieldvalue("estimated value") as double?) ?? 0),
agreementtypeid = sphelper.getfirstlookupid(item.getspfieldvalue("contract type"))
};
}
var action = result.getsplistitems()
.select(item => item.tomyaction())
.firstordefault();
//var action = (from item in result.getsplistitems()
// select item.tomyaction()).firstordefault();
score:2
action = (from listitem in result.getsplistitems()
select new action
{
title = listitem.getspfieldvalue("title"),
description = listitem.getspfieldvalue("description"),
deliveryorderid = sphelper.getfirstlookupid(listitem
.getspfieldvalue("delivery order")),
estimatedvalue =
((listitem.getspfieldvalue("estimated value") as double?) ?? 0),
agreementtypeid = sphelper.getfirstlookupid(listitem
.getspfieldvalue("contract type")),
}).firstordefault();
Source: stackoverflow.com
Related Query
- How to use LINQ to query from a list of objects into an existing object?
- How to use LINQ to get an object from List of objects matching option from List of options
- Can I use LINQ to create a new list of objects from an existing list
- How to use LINQ to query list of strings that do not contain substring entries from another list
- How to use Linq to select and group complex child object from a parents list
- How can you use LINQ to cast from a collection of base class objects to a filtered list of their respective subclasses?
- How to use LINQ to query for specific object in an array in a list of objects?
- How to use Linq to check a list of objects property have allowed values from another list
- How to get multiple column value from database into a list using LINQ query
- List of objects where the object contains an array - how to use LINQ to search through all objects for a value in that array
- How to execute a linq query for each item in a list , use it in the where clause and return a collection from the result of each query?
- Return a specific object in a LINQ select query from two different objects in a list
- How to return an object (or a list of objects) of anonymous type from a LINQ query to the UI (Console App) in C#?
- How do I use LINQ to obtain a unique list of properties from a list of objects?
- LINQ query to return distinct field values from list of objects
- Linq select object from list depending on objects attribute
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- LINQ Query - How to map a resultset into another object using Select
- Linq query a List of objects containing a list of object
- How can I use LINQ to project this parent and children object model into a flat, single object?
- Linq - merging sub lists from different objects into a single object
- how do i use group by only on date from datetime in LINQ query
- Use C# Linq Lambda to combine fields from two objects into one, preferably without anonymous objects
- How to create a list from filtering 2 lists with linq to object
- Query in returning Objects from List using LINQ
- Return Linq query results into List object
- How to fill a property of an object from another list using LINQ
- LINQ query using list of objects property of an object
- How to return linq query into single object
- How can I speed up this linq query on a List<> with search criteria on 3 attributes in the list object
More Query from same tag
- Split string into list of N-length strings using LINQ
- linq to entity,How does the where clause use ?: Expression
- Possible to do this in linq?
- System.Linq Linq queries not working in VS2012 but works fine in VS2010
- XML Literals LINQ - use variables in Enumerable.Range(int, int)
- Retain DataGridView metadata after clearing DataSource
- Linq help using "Contains"
- use linq to group by and then run select query with where condition
- Sitecore ContentSearch LINQ Unsupported expression node type: Parameter
- How to get only User's from a Group that contains nested Groups using Microsoft Graph API?
- The cast to value type 'System.Int32' failed because the materialized value is null.
- Get top max item by linq
- C# Load XML values to dictionary with name as index
- Build LINQ Select conditionally similar of using PredicateBuilder for Where clause
- Concatenating two lists of different types with LINQ
- Why does orderbydescending not rearranged a list?
- How can I select from a collection with LINQ?
- Using LINQ with wildcard characters without using SqlMethods
- Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IOrderedEnumerable
- Is looping through IQueryable the same as looping through a Datareader with Reader.Read() in C#
- Two way binding in WPF trough LINQ to SQL for the property of a ListItem of a ListBox using a DataTemplate
- How do I get an object from a relational database with LINQ?
- how to change the type of the parameter in an Expression?
- Refactor two linq queries into one single query
- C# LINQ append an item to the end of an array
- How to handle return of List<AnonymousType>?
- Query and Assignment in a Single Step
- LINQ query to Group, Sort and SumProduct
- Comparing 2 string arrays using Linq and Regex for a partial match
- What if IEnumerable<string> returns just one string