linq

LINQ to SQL - Left Outer Join with multiple join conditions

I have the following SQL which I am trying to translate to LINQ: SELECT f.value FROM period as p LEFT OUTER JOIN facts AS f ON p.id = f.periodid AND f.otherid = 17 WHERE p.companyid = 100 I have seen the typical implementation of the left outer join (ie. into x from y in x.DefaultIfEmpty() etc.) but am unsure how to introduce the oth...

Retrieve a list containing NULLS with Linq

Is it possible to use LINQ to retrieve a list that may contain nulls. For example if I have a left outer join like so: var query= from c in db.Customers join o in db.Orders on c.CustomerID equals o.CustomerID into sr from x in sr.DefaultIfEmpty() select x.OrderId; Ho...

where to find a small example/demo on how to create a LINQ Provider?

Hi i was wondering if you have had seen a quick demo on creating a LINQ Provider. Thanks, Oscar ...

Linq: What is the difference between == and equals in a join?

I always wondered why there's an equals keyword in linq joins rather than using the == operator. Property deadline = (from p in properties join w in widgets on p.WidgetID equals w.ID select p).First(); Instead of Property deadline = (from p in properties join w in widgets on p.WidgetID == w.ID select p).First(); [EDIT] Rephra...

SubSonic 3 ActiveRecord lambda expression partially ignored on delete

I have tables Users, Widgets and Layouts. Users have many-to-many relationship with Widgets via Layouts. Each Layout has UserID and WidgetID. I want to delete a Layout that matches specific UserID and WidgetID. Using SubSonic 3 ActiveRecord I write: Layout.Delete(x => x.UserID == user.id && x.WidgetID == id); However, SubSonic delete...

Trouble with a LINQ 'filter' code throwing an error

Hi folks, I've got the following code in my Services project, which is trying to grab a list of posts based on the tag ... just like what we have here at SO (without making this a meta.stackoverflow.com question, with all due respect....) This service code creates a linq query, passes it to the repository and then returns the result. N...

"where" query using linq xml

hi, been taxing my brain trying to figure out how to perform a linq xml query. i'd like the query to return a list of all the "product" items where the category/name = "First Category" in the following xml <catalog> <category> <name>First Category</name> <order>0</order> <product> <name>First Product</name> <...

Default if empty with LINQ to entities

In a LINQ to entities expression like this: var vote = (from vote in db.Vote where vote.Voter.Id == user.Id select v).FirstOrDefault(); how do you you add a DefaultIfEmpty so that when there's no vote I'd get a default value? ...

ApplyPropertyChanges and References.

I asked this question earlier but I think I phrased it incorrectly, so here is attempt number two. I have the following code: public User EditUser(User userToEdit) { //userToEdit contains values for eagerly loaded contacts entity User originalUser = (from u in _entities.UserSet.Include("contacts") ...

Silverlight application architecture

I just started learning Silverlight, and I'm wondering about the typical architecture of a Silverlight application and the workflow in the application (I'm using Silverlight 2, but will move to 3 any time soon). In my test-application I currently only have the two default projects - MyProject and MyProject.Web. I'm familiar with the MV...

Linq to Sql Skip function problem?

Hello I have a problem with Skip function.. I code I have for fetching data is db_stamperDataContext context = new db_stamperDataContext(); //var modifier = (from m in context.Modifiers // where m.Modifier1 == "Public" // select m).First(); //var item = from p in context.It...

SubSonic 3 and Linq Parameterized Queries

We are currently using SubSonic 3.0.0.2 and playing about with the Linq for it, we've noticed that the underlying SQL is not parameterized. I'm aware that the query tool is and we can work with that but I'm just curious if having parameterized with Linq is possible? Am I missing something? or is this not yet implemented in SubSonic. ...

Lambda Expression of Select * from TableName

Hi All, I just want to know what's the lambda expression of Select * from TableName. Like in plain LINQ it will be var res=from s in db.StudentDatas select s; here StudentData is name of the table. Thanks. ...

LINQ - Sort List of objects using OrderBy EnumValue, and Union result set?

Greetings! I want to use LINQ to query a list of objects and sort them by an enumeration value, string value then union the rest of the list sorted in a similar fashion LINQ newbie here, so be gentle. //CTOR for my class MyClass(id, "Name Value Here", Enum.EnumValueHere); I create a list of these objects and want to variably sort th...

LINQ Refresh does not result in Changed Events

Is it just me or does changes produced by refreshing the LINQ DataContext not result in Changed Events? I have a multiuser Application which has an simple atomar locking system to prevent conflicts. So if an User changes something in the database I need to trigger Refresh on the Datacontext to reload the concerning objects. A breakpoin...

LINQ to objects cast result of query

Hello there, i have a class user, and i also have implemented a collection for the same user class - users. users will store user objects. users collection class implements the generic collection class - collection. i want to cast the LINQ query result into an object of my collection class - users. Everytime i try explicit casting, it ...

C# - Finding the common members of two List<T>s - Lambda Syntax

So I wrote this simple console app to aid in my question asking. What is the proper way to use a lambda expression on line 3 of the method to get the common members. Tried a Join() but couldn't figure out the correct syntax. As follow up... is there a non-LINQ way to do this in one line that I missed? class Program { static void Mai...

How to use two ordering criteria in C#?

I have a set of strings. I want to select all strings that contains another string. But I want to have as the first items, the items that start with the search, and then, alphabetically the other items. But the following code doesn't work: items = items .Where(a => a.Contains(contained)) .OrderBy(a => a) ; var startsWith = item...

Bind LINQ data via stored procedure to Gridview

The function in dbml is, [Function(Name = "dbo.sp_GetQuestions")] public ISingleResult<vw_QuestionMaster> sp_GetQuestions([Parameter(Name = "Sort", DbType = "Int")] System.Nullable<int> sort, [Parameter(Name = "Title", DbType = "VarChar(50)")] string title, [Parameter(Name = "Tags", DbType = "VarChar(50)")] string tags, [Paramet...

Posttorial: ASP.NET MVC, Entity Framework and LINQ video tutorials - Including MIX09, PDC, TechED

EDIT: During this post I started searching on video tutorials on ASP.NET MVC, EF and LINQ and found some very useful links which I shared here. As I believe videos are more interactive and easier to learn from. Hope, they'll help. Guys, please share the resources to get start on MVC, Entity Framework and LINQ. And if you...