linq

How does cast in C#/.NET 3.5 work for types with '?'

Possible Duplicate: Nullable types and the ternary operator. Why wont this work? This is my code which works public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : (decimal?) null; } and this one doesn't work public decimal? Get() { var res = ... return res.Count() > 0 ? res.First() : ...

LINQ, "Argument types do not match" error, what does it mean, how do I address it?

Hello, I'm new to linq and I'm trying to databind to an anonymous type. I'm using SubSonic 3.0 as my DAL. I'm doing a select from 2 tables like so var myDeal = (from u in db.Users select new { UserID = u.UserID, UserRoleID = (from ur i...

Taking 2 attributes from XElement to create a dictionary LINQ

I'm trying to take one attribute to use as the key, and another to use as the value. If I use (xDoc is an XDocument object in the example): Dictionary<string, XElement> test = xDoc.Descendants() .Where<XElement>(t => t.Name == "someelement") .ToDictionary<XElement, string>(t => t.Attribute("myattr").Value.ToString()); I get a ...

LINQ reformat to Table in Memory

Hello all, I am working on an ASP.net page that also users ChartFX. I need to pull a row from a database table and then flip it so that all of the labels for the row are in a column and all of the data from the row is in a parallel column to the labels. I would really like to do this using LINQ and then create a table in memory to store...

How to write an "OR" within a Linq to Sql .Where()

I want to get all records WHERE (s.override == 1 OR (s.override == 2 AND s.approved == 1)) How can I do that using the .Where x.subcontracts.Where(s ==> ??) ...

LINQ aggregate across more than one table

I want to replicate this query in LINQ to SQL but am too unfamiliar with how to do it. SELECT A.Recruiter, SUM(O.SaleAmount * I.Commission) --This sum from fields in two different tables is what I don't know how to replicate FROM Orders AS O INNER JOIN Affiliate A ON O.AffiliateID = A.AffiliateID INNER JOIN Items AS I ON O.ItemID = I.I...

LINQ Foreign Key Relationship Naming (Address, Address1, Address2)

Hello, is it possible to change the foreign key relationship object naming of LINQ to SQL generated objects? For example, I have a Demo table which has the fields ItemMinId, ItemMaxId, ItemExlId which are all foreign key references to my Item table. LINQ generates now Demo.Item, Demo.Item2, Demo.Item3 fields which makes it difficult in...

Linq to Sql Projection Help

I've reached the end of my Linq rope. Need your help! Heres my table structure first(all linq to sql objects): InventoryItems -ID -AmtInStock IventoryKits -ID InventoryKits_to_InventoryItems -InventoryItemID -InventoryKitID So i need to do a projection like the following var q2=from k in GetAllKits()//returns IQueryable...

Add LINQ Auto-Generated Value Marker [Column(IsDbGenerated=true)] in Buddy Class

Hello, is it possible to decorate a field of a LINQ generated class with [Column(IsDbGenerated=true)] using a buddy class (which is linked to the LINQ class via [MetadataType(typeof(BuddyMetadata))]) ? My goal is to be able to clear and repopulate the LINQ ORM designer without having to set the "Auto Generate Value" property manually ev...

What is the return type for a anonymous linq query select? What is the best way to send this data back?

This is a basic question. I have the basic SL4/RIA project set up and I want to create a new method in the domain service and return some data from it. I am unsure the proper easiest way to do this.. Should I wrap it up in a ToList()? I am unclear how to handle this anonymous type that was create.. what is the easiest way to return this ...

Help with Subsonic3 ActiveRecord LINQ query

I have the following subsonic entities TInvoiceHeader TAccountAssociation How can I achieve the following in LINQ (subsonic) SELECT * from TInvoiceHeader WHERE custid IN (SELECT custid FROM TAccountAssociation WHERE username = 'a') I need to bind the results to a GridView. Update: I tried Dim accounts As List(Of TAccountA...

How to get an array of members of an array

Suppose I have a class public class Foo { public Bar Bar { get; set; } } Then I have another class public class Gloop { public List<Foo> Foos { get; set; } } What's the easiest way to get a List<Bar> of Foo.Bars? I'm using C# 4.0 and can use Linq if that is the best choice. UPDATE: Just for a little dose of reality, the ...

What is difference between Where and Join in linq ?

hello What is difference between of these 2 queries ? they are completely equal ? from order in myDB.OrdersSet from person in myDB.PersonSet from product in myDB.ProductSet where order.Persons_Id==person.Id && order.Products_Id==product.Id select new { order.Id, person.Name, person.SurName, product.Model,UrunAdı=produc...

how to check whether xml file has access or not in c#?

i am saving dafault values in an xml file. if i dont have access to the xml file i should show message in the status bar ...

How can I load class's part using linq to sql without anonymous class or additional class?

class Test { int Id{get;set;} string Name {get;set;} string Description {get;set;} } //1)ok context.Tests.Select(t => new {t.Id, t.Name}).ToList().Select(t => new Test{Id = t.Id, Name = t.Name}); //2)ok class TestPart{ int Id{get;set;} string Name {get;set;} } context.Tests.Select(t => new TestPart{Id = t.Id, Name = t.Name...

Linq Expression Trees in Compact Framework.

The lack of expression trees in Compact Framework has bugged me for some time now, but I haven't really looked for a solution. Today, I've found a blog post about an alternative System.Linq.Expressions built on top of Mono System.Core and used e.g. by db4o (you can find it here). My question is - have you used this library and if so,...

how to check whether xml file content is in correct format?

i have one default.xml file where i am storing all default values.suppose if invalid file with the same default.xml name exists i have to display message in the status bar. ...

check existense between two IEnumerable

IEnumerable<String> existedThings = from mdinfo in mdInfoTotal select mdinfo.ItemNo; IEnumerable<String> thingsToSave = from item in lbXReadSuccess.Items.Cast<ListItem>() select item.Value; Here are two IEnumerable. I want to check whether a value in existedThings exist in thingsToSave. O.K. I can do that with 3 li...

LINQ - Using where or join - Performance difference ?

Hi Based on this question: http://stackoverflow.com/questions/3013034/what-is-difference-between-where-and-join-in-linq My question is following: Is there a performance difference in the following two statements: from order in myDB.OrdersSet from person in myDB.PersonSet from product in myDB.ProductSet where order.Person...

Check Directories in C# using Linq

Can someone tell me what I'm doing wrong with the following Linq query? I'm trying to find the directory with the highest aphanumerical value. DirectoryInfo[] diList = currentDirectory.GetDirectories(); var dirs = from eachDir in diList orderby eachDir.FullName descending ...