Well I have a string now that has the expression value to be evaluated..it has say value "expr=expr.FieldName"... so I want to use this string as Linq.Expression or any other way to query...like Select(str). Please help me out.
In sql server, we can issue sql to get data like
select * from table where column like '%myword%'
select * from person where Soundex(LastName) = Soundex('Ann')
what's the linq query to match above sql?
I have a groupby that I groups all elements. I can see the items are there in LinqPad but can't find a way to get the count.
Here is what I have so far:
SurveyResponses.Where( q = q.QuestionId == 4).GroupBy(q = q.AnswerNumeric).Where( g = g.Key == 1)
In Linq Pad I can see there are 4 items in this query. If I do Count it returns 1. I've tried, ToList().Count, Select(x = x).Count, etc.
Hi,
I have the following LINQ example:
var colorDistribution =
from product in ctx.Products
group product by product.Color
into productColors
select
new
{
Color = productColors.Key,
Count = productColors.Count()
};
All this works and makes perfect sense.
What I'm trying to achieve is to group by into a strong type instead of anonymous type.
For example I have a ProductColour class and I would like to Group into a List<ProductColour>
Is this possible?
Thank you
I have the following LINQ that I would like to also order by file creation date, how is this done?
taskFiles = taskDirectory.GetFiles(Id + "*.xml")
.Where(fi => !fi.Name.EndsWith("_update.xml", StringComparison.CurrentCultureIgnoreCase))
.ToArray();
For example, imagine that I want to see if a user exists in my database:
Select * from Users where inputID = Users.ID
Then if that result brought 0 items, then the user exists, correct?
How can I do something like this using a pure Linq-to-SQL class?
LINQ to SQL internally generates SQL queries and fire on the database after submitting changes. Is there any way we can wrap all these queries in some stored procedure and execute this store proc everytime when anything gets inserted or updated in the database.
Problem is only stored procedures are allowed to carry any insert or update or delete operations, direct queries are restricted for security purpose.
string candidates = new string[] {
"Luke_jedi", "Force_unknown",
"Vader_jedi" , "Emperor_human", "r2d2_robot"
};
string[] disregard = new string[] {"_robot", "_jedi"};
//find those that aren't jedi or robots.
var nonJedi = candidates.Where(c=>
c.??? //likely using EndsWith() and Any()
);
How would you implement this solution using LINQto find all those that do not end with any of the disregards items?
How can I find out if a Linqto SQL entity has grandchildren or not?
Pseudo-code below:
Return From p In dc.Processes Where p.Signers.Count > 0 and p.Signers.Signatures.Count > 0
Obviously I can't run the code above but I need to make sure that all the returning Processes have at least one Signer and that all of those Signers have at least one Signature.
TIA!
The scenario is I want to get the users who has less than 2 photos.
There are two table:
[Users] (UserId, UserName)
[UserPhotos] (PhotoId, PhotoName, UserId)
UserId is a Foreign Key but I do not want to use association like user.Photos.
A user may have none photo in the [UserPhotos] table.
How to use LinqTo Sql to get List<User> who has less than 2 photos?
Given an IList<Foo> with a data set that looks like this:
ID CHILD PARENT TYPE
1 102 101 UPSELL
1 103 101 UPSELL
2 102 101 BONUS
2 104 103 BONUS
3 102 101 BONUS
4 102 101 PRODUCT
4 104 102 PRODUCT
How can I use LINQto find the intersection of Parent and Child values withing each ID?
Desired output is
ID CHILD PARENT TYPE
4 102 101 PRODUCT
I'm converting from C# this LINQ expression. However, it does not seem to work.
C#
return (from w in fishSticks
group w by w.FishQty into g
orderby g.Key descending
select g).First().First();
VB
Return (From w In fishSticks
Group w By w.FishQty Into g()
Order By g.Key Descending
Select g).First().First()
Visual Studio turns g into g() itself and then gives me this error:
Definition of method 'g' is not
accessible in this context.
Any ideas?
Hi, could you help me please convert this SQL query toLinqto Entity query? Thank you
select distinct item, count(item) as count
from TableName
where ColumnName = @parameter and (ColumnName2 = @parameter2 OR ColumnName3 = @parameter3)
group by item order by item asc
I was wondering if anyone knew why linqto entities always seems to generate left outer joins. I would understand it on an optional relationship but it doesn't make good sense when the relationship is mandatory.
Does anyone have any idea how to make it generate inner joins instead?
In the following code I am using XPath to find all of the matching nodes using XPath, and appending the values to a StringBuilder.
StringBuilder sb = new StringBuilder();
foreach (XmlNode node in this.Data.SelectNodes("ID/item[@id=200]/DAT[1]/line[position()>1]/data[1]/text()"))
{
sb.Append(node.Value);
}
return sb.ToString();
How do I do the same thing, except using Linqto XML instead? Assume that in the new version, this.Data is an XElement object.
I read that PLinq will automatically use non parallel Linq if it finds PLinq to be more expensive. So I figured then why not use PLinq for everything (when possible) and let the runtime decide which one to use.
The apps will be deployed to multicore servers and I am OK to develop a little more code to deal with parallelism.
What are the pitfalls of using plinq as a default?
The scenario is I want to get the users who has more than 2 photos.
There are two table:
[Users] (UserId, UserName)
[UserPhotos] (PhotoId, PhotoName, UserId) and UserId is a Foreign Key.
A user may have none photo in the [UserPhotos] table.
How to use LinqTo Sql to get List who has more than 2 photos?
I would like to allow two threads to write in a table at the same time (I know the problem of updating the same row, but this would be a story apart). I need that in behalf of speed up the operations in my aplication (one thread could write in row X while another could do the same in row X+n instead of waiting the first to finalize).
So, can I block rows instead of tables with Linqto SQL?
Thanks.
Query:
select emp.empname as Name, dep.depname as Department
from Employee as emp
inner join Department as dep on emp.depid=dep.depid
where emp.id='2'
How can I change this tolinqto sql?
Imagine you have int[] data = new int [] { 1, 2, 1, 1, 3, 2 }
I need sub-array with only those which conform to a condition data[i] data[i-1] && data[i] data[i + 1]... i.e. I need all items which stick over their immediate neighbours.
From example above I should get { 2, 3 }
Can it be done in LINQ?
Thanks
LINQ to SQL .Count takes way to much process time and decreases performances.
I am doing a recursive loop and for one child (lets call it parent) I have to check the number of children under it to make a decision if it should be included or not.
The Count is too slow 8 ms :( for 120 parent records.
Any ideas to make it quicker.
What is the difference between Equals and = in LINQ?
Dim list As List(Of Foo) = (From a As Foo In FooList _
Join b As Bar In BarList _
On a.Something = b.Something _
Select a).ToList()
versus
Dim list As List(Of Foo) = (From a As Foo In FooList _
Join b As Bar In BarList _
On a.Something Equals b.Something _
Select a).ToList()
Hello guys
does anyone know how to convert this SQL statement to a LINQto a List?
SELECT TOP(5) COUNT(CategoryId), CategoryName
FROM Tickets
GROUP BY CategoryName
The result would be something like
public static List<Categories> List()
{
MyEntities db = new MyEntities();
/* here it should return a list o Category type */;
return db.Category.GroupBy(...).OrderBy(...);
}