I'd like to do the equivalent of the following in LINQ, but I can't figure out how:
IEnumerable<Item> items = GetItems();
items.ForEach(i => i.DoStuff());
What is the real syntax?
If I want to get a user that has the email address of '[email protected]', how do I pass that as a parameter in linq?
ie.:
var a = from u in Users
where u.Email = @email
Select u;
So this would be used in my method:
public static GetuserByEmail(string email)
Do I just pass in the variable or?
I am using VS2010 and C#
When I map/select my database tables with LINQto SQL I have to option to change the "member" propery, but when i delete the table (because I changed something in the schema for example) and add it again the member value gets "reset". Is it possible to set/override this member programmaticly, so that I dont have to change it by hand everytime
I mean the member option of
'<'Table Name="dbo.table1" Member="table1"
I have struggled converting this SQL statement toLINQto SQL VB.Net 9.0. I have used Linqer but no success. Any help would be appreciated
select t.TeeId,
t.DescriptionId,
t.[Description],
t.Rating,
t.Slope,
case when d.TotalHoles <> h.TotalHoles then 0
else 1 end [Status]
from dbo.CourseDescription d
inner join dbo.CourseTees t
on t.DescriptionId = d.DescriptionId
inner join (select TeeId, count(*) as TotalHoles
from dbo.CourseHoles
group by TeeId) h
on h.TeeId = t.TeeId
where d.CourseId = 1
I'm looking for the full list of supported linq extension methods that are compatible with WCF Data Services.
By trial and error I've found First() and Single() aren't supported, any others?
This gives me a pretty good idea of whats supported, I just don't know whats actually translated via the IQueryProvider.
The folloqing is the excpetion I am getting
The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type.
below is my LINQ Statement where QuestionId is the primary key in my table
var questionViewsData = from questionViews in objDc.SC_QuestionsViews
join questions in objDc.SC_Questions
on questionViews.QuestionId equals questions.QuestionId into qs
from questions in qs.DefaultIfEmpty()
where questionViews.CreatedDate.Date == new DateTime(2010, 4,27)
select new
{
Selected =(questions == null ?-1:questions.QuestionId),
QuestioinTitle = questions.Title,
VotesCount = questions.VotesCount
};
Let me know how to resolve this
Hi,
I had asked this question
http://stackoverflow.com/questions/2442149/adding-more-attributes-to-linq-to-sql-entity
Now, when I add Browsable attribute to generated entity in designer,it works.But,when I use the MetaDataType approach,and add Browsable attribute in partial class,it does not work
"I added a MetaDataType class, and added browsable attribute to property,but seems to have no effect"
How do I retrieve all elements after the first one starting with a "-" using linq?
var arr = new[] {"-s1", "-s2", "va", "-s3", "va2", "va3"};
var allElementsAfterVA = from a in arr where ???? select a;
I want allElementsAfterVA to be "-s3", "va2", "va3"
Here's the query i'm trying to convert into Linq:
SELECT R.Code,
R.FlightNumber,
S.[Date],
S.Station,
R.Liters,
SUM(R.Liters) OVER (PARTITION BY Year([Date]), Month([Date]), Day([Date])) AS Total_Liters
FROM S INNER JOIN
R ON S.ID = R.SID
WHERE (R.Code = 'AC')
AND FlightNumber = '124'
GROUP BY Station, Code, FlightNumber, [Date], Liter
ORDER BY R.FlightNumber, [Date]
Thanks for any help.
I have a scenario where I would want a plugin to construct a LINQ (to objects) query, send it across an appdomain and then apply and run it against a collection of my choosing
Is it possible, how?
If not, perhaps I could send a whole method (interface) across the appdomain and run it against the data on the appside? The main thing is that I want the data to reside in the CurrentDomain and the logic for operating on it in the plugin so I don't have to send the data across the boundary...
i have one independent form where i am checking read only access of an xml file ,
if the file is read only then i have to display message in the status bar of MDI form.
since i am using independent form to valid xml file, status bar of the MDI form is not displaying the error message.
now how to display message?
thanx in advance
I can't figure out why I get a Object reference not set to an instance of an object. error if I use a ternary operator in my LINQ query.
var courses = from d in somesource
orderby d.SourceName, d.SourceType
select new
{
ID = d.InternalCode,
Name = string.Format("{0} - {1}{2}", d.InternalCode, d.SourceName, (d.SourceType.Length > 0 ? ", " + d.SourceType : string.Empty))
};
Any thoughts?
I'm usig tablesorter jQuery to parse this xml file
<?xml version="1.0" encoding="iso-8859-1"?>
<CATALOG>
<CD>
<TITLE>Title 01</TITLE>
<ARTIST>Artist 01</ARTIST>
<COUNTRY>Country 01</COUNTRY>
<PRICE>10.00</PRICE>
<YEAR>2010</YEAR>
<INFO>Tooltip Info 01</INFO>
</CD>
<CD>
<TITLE>Title 02</TITLE>
<ARTIST>Artist 02</ARTIST>
<COUNTRY>Country 02</COUNTRY>
<PRICE>9.00</PRICE>
<YEAR>2009</YEAR>
<INFO>Tooltip Info 02</INFO>
</CD>
<CD>
<TITLE>Title 03</TITLE>
<ARTIST>Artist 03</ARTIST>
<COUNTRY>Country 03/COUNTRY>
<PRICE>8.00</PRICE>
<YEAR>2008</YEAR>
<INFO>Tooltip Info 03</INFO>
</CD>
</CATALOG>
and with this code
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "GET",
url: "file.xml",
dataType: "xml",
success: function(xml){
$(xml).find("CD").each(function(){
$("#tablebody").append('<tr><td>'
+ $(this).find("TITLE").text()
+ '</td><td>'+ $(this).find("ARTIST").text()
+ '</td><td>'+ $(this).find("COUNTRY").text()
+ '</td><td>'+ $(this).find("PRICE").text()
+ '</td><td>'+ $(this).find("YEAR").text()
+ '</td></tr>');
});
}
});
});
</script>
I'm new at javascript and have been trying with no luck for a couple of hrs to get the text from the INFO/INFO tags in the xml file to show as title attributes for each table row. The reason for that is that I need to have individual popup tooltips on mouse-over each table row.
Many Thanks in advance for any kind of help or suggestions!
Im using linq-sql .I have 3 tables. e.g
Project, People and a ProjectsPeople(fk's ProjectID and PeopleID) (junction) Table.
given a set of peopleIDArray (an array of ints as people ID's)
how can i get only Projects that have atleast one of the peopleId's associated with them?
i.e there will be atleast one (may be more) record in the ProjectsPeople table that will have a ProjectId and an id from the peopleIDArray )
thanks
I need to know if the List I am working with contains only some specific values.
var list = new List<string> { "First", "Second", "Third" };
If I want to know if the List contain at least one item with the value "First" I use the Any keyword:
var result = list.Any(l => l == "First");
But how I can write a Linq expression that will return true/false only if the List contains "First" and "Second" values?
Hi,
I don't see a LINQ option when picking a data source for a grid view - any ideas?
I just upgraded to Visual Web Developer 2010. I see the other options like SQL etc.
Thanks!
Hi All,
i am trying to figure out how to write a linq query that will return a child collections "name" property as a string.
I have a BO that has a "options" property where the options are the "name" property of each option in an "order" object.
I would like the result to look something like
order.id = 12312
order.date = 12/03/10
order.options = "Option 1 Name, Option 2 Name, Option 3 Name"
I hope this makes sense. thanks for any and all help!
I have a need to load an entire LINQ-to-SQL object graph from a certain point downwards, loading all child collections and the objects within them etc. This is going to be used to dump out the object structure and data toXML.
Is there a way to do this without generating a large hard coded set of DataLoadOptions to 'shape' my data?
I have this linq query:
var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts
on new {s.ID, settings.GruppoSegreteria}
equals new {h.USR_UtentiReference,h.ID_Gruppo} select s;
that has this problem:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
how can i do to solve it?
Given a list of objects with a date and decimal, I would like to index these objects by the year, month, dayofweek and hour of the date. In .NET 2.0, I would have created this graph using a set of nested dictionaries and a list as the leaf node. I am interested in how this could be done with LINQ.
Hello everybody
I have a user entity who contains a one to many relationship with a role entity
So with this linq expression :
from user in USER_TABLE.Include("USERROLE_TABLE")
order by user.Name
select user
I can get users with related roles as a child.
My problem is that i want to get roles of each user ordered alphabetically.
How can i do that ? I googled a lot and don't find anything
Thank's by advance !
I have the following linq query
from o in context.Opportunities
join i in context.Interactions on o.OpportunityID equals i.OpportunityID into ints
from i in ints.DefaultIfEmpty()
orderby i.StatusID descending, o.StatusID descending
select o
Now i want to then do a distinct on the opportunities table but doing so removes my orderby. I know that you can do Distinct().OrderBy but how do i get a reference to the interactions table that was joined when I'm only selecting the opportunity entity?
I have a collection:
List<Car> cars=new List<Car>
Cars are uniquely identified by CarCode.
I have three cars in the collection, and two with identical CarCodes.
How can I use LINQto convert this collection to Cars with unique CarCodes?
How can I use linq in C# to select the columns of a jagged array of ints, I select the rows as follows.
int[][] values;
....
var rows = from row in values select row;
Thank you for the help.
I have an object allStudents=Dictionary()
In Linq how would I get a list of all the students who are male? (student.Gender=="m") from all the Classrooms?
Ian