I'm writing a custom LINQ provider to a RESTful service. Some of the calls in the service return summary headers, including total number of records, pagesize, and the page of the return. I need clean a way to return this data. Given this query:
var foo = from x in ctx.MyQueryableThingie
select x;
The "foo" variable above b...
The fake code is:
public class ParentClass
{ decimal quantity,
decimal price
}
IQueryable<ParentClass> parents;
//SonClass is created at run time
//SonClass has some extra property, such as amount=quantity*price, which is defined by a string at run time
IQueryable<SonClass> sons=parents.Select(p=>new S...
I have an array of Car objects
I want to conver them to a list of Vehicle objects
I thought this would work
Vehicle[] vehicles = cars.ConvertAll(car=> ConvertToVehicle(car)).ToArray();
but its complaining that ConvertAll requires two parameters.
here is the error:
Error 2 Using the generic method 'System.Array.ConvertAll(TInput[...
How can i use insert into myTABLE (. . . .. . ) select * from(.......). I try to write some linq query but i can not. Look please linq query.
SQL:
INSERT INTO ActualAmountsByLocation (ItemBarcode, Location, LocationName, Amount, isCustomerItem, LastUpdate)
SELECT * FROM
(SELECT DISTINCT
m.ItemBarcode,
...
What is the purpose of LINQ?
Where LINQ can be used?
How necessary is it to learn the LINQ?
What is the best way to learn LINQ?
...
I get the error :
A local variable named 's' cannot be
declared in this scope because it
would give a different meaning to 's',
which is already used in a 'child'
scope to denote something else.
static void Main(string[] args)
{
string s = "hello"; // Line 1
var test = new[] { "abd", "def" }.Select(s => s.StartsWith...
how can i write "in( select" method in linq?
I'm trying to convert :
UPDATE ActualAmountsByLocation SET isCustomerItem=1 WHERE ItemBarcode IN (SELECT barcode FROM StockMaterials WHERE barcode=@Barcode AND ownership=1)
I've tried like this:
Array stockMaterials = ( from s in stockMovementCtx.StockMaterials where s.barcode == Barc...
I have the following class:
public class MyClass<T> where T : class
{
public void Method1<TResult>(T obj, Expression<Func<T, TResult>> expression)
{
//Do some work here...
}
public void Method2<TResult>(T obj, Expression<Func<T, TResult>> expression1, Expression<Func<T, TResult>>...
I have a piece of code which combines an in-memory list with some data held in a database. This works just fine in my unit tests (using a mocked Linq2SqlRepository which uses List).
public IRepository<OrderItem> orderItems { get; set; }
private List<OrderHeld> _releasedOrders = null;
private List<OrderHeld> releasedOrders
...
DealsThisMonthOpen = deals.Where(deal => deal.DateCreated.Month == date.Month && deal.DealStatus == "Open").Count(),
DealsThisMonthLost = deals.Where(deal => deal.DateCreated.Month == date.Month && deal.DealStatus == "Lost").Count(),
DealsThisMonthWon = deals.Where(deal => deal.DateCreated.Month == date.Month && deal.DealStatus == "Won")...
If I have used LINQ's GroupBy() method to create a grouped enumeration, is it possible to regroup that result under another key system? That is, if I grouped all of the objects by property X for one part of the code, is it possible to subsequently group that collection by property Y of property X at a later point in the code?
...
I have two custom classes, ChangeRequest and ChangeRequests, where a ChangeRequests can contain many ChangeRequest instances.
public class ChangeRequests : IXmlSerializable, ICloneable, IEnumerable<ChangeRequest>,
IEquatable<ChangeRequests> { ... }
public class ChangeRequest : ICloneable, IXmlSerializable, IEquatable<ChangeRequest>...
Any time I use the code below it throws the error:
Method 'System.String
Join(System.String,
System.Collections.Generic.IEnumerable`1[System.String])'
has no supported translation to SQL.
var items = from t in fc.table
where t.id== objId
select new
{
...
My project has the following setup
Controller -> Service (for validation) -> Repository (for LINQ) -> dbml -> Database
Controller
''# <AcceptVerbs(HttpVerbs.Post)> - hiding this line so that code formatting looks proper in SO.
Function Edit(ByVal user As Domain.User, ByVal id As Integer) As ActionResult
If ModelState.IsVali...
How can I query a collection for a keyword like "John Doe" where the value of a property might be "John M Doe"? Doing a contains certainly will not work but below is an idea of what I'm after. people, for reference, is a List containing Person objects that have Name and Description properties.
string keyword = "John Doe";
var q = from...
This question is very similar to a previous question of mine, Use LINQ to count the number of combinations existing in two lists, except with some further twists.
I have a list of CartItems that can receive a discount based on the items specified in the list of DiscountItems. I need to be able to pull out the items in the Cart that c...
Hi,
i have a namespace string like "Company.Product.Sub1.Sub2.IService".
The Sub1/Sub2 can differ in their count, but normally their is one part which matches to
a Dictionary with AssemblyFullname as key and path to it as value.
Now ive written this code
string fullName = interfaceCodeElement.FullName;
var fullNamePart...
I have some code that groups a table by "Value1" and some loops that add the top row of each group to a list. This is a pretty ugly way to do this, and I was wondering if I could replace one of the foreach loops with a couple more lines in my LINQ query? Problem is, I don't have the foggiest idea how to do this.
var Result =
from a in...
So I want to access the child element in a structure that looks like this:
<asdf:foobar attr="value">
<child>...</child>
</asdf:foobar>
I forget what the asdf is called, but it is what's causing the problem. My normal method of traversing in XLinq doesn't work:
xElem child = xDoc.Element("foobar");
Sets child to null because it...
I'm at a bit of a loss here. I'm creating a collection of objects from another collection using LINQs .Select and then using .OrderBy to get an IOrderedEnumerable. This part works fine, but when I loop over this with foreach and set a property on the object in the collection, the object in the collection is not modified.
I'm writing a...