linq

How to access data into IQueryable??

I have IQueryable object and I need to take the data inside the IQueryable to put it into Textboxs controls. Is this possible? I try something like: public void setdata (IQueryable mydata) { textbox1.text = mydata.???? } Update: I'm doing this: public IQueryable getData(String tableName, Hashtable myparams) { decimal ...

ADO.NET Entity 1:1 Navigation Property

Is there a way to get ADO.NET Entity to generate 1:1 navigation properties? If I do foreign keys I always get 1:N navigation properties. ...

I just don't understand how to use Linq

I have a class as follows: Class Scan Delivered As Boolean ScanDate As Date State As String Facility As String End Class I then create a list and populate it with scans containing whatever. Dim Scans As New List(Of Scan) I need to mine the list to get various pieces of information. I would like to use LINQ to do ...

prefetching members of inherited entities via a LINQ-to-Entities query

I think the simplest way I can ask this question is with an example: Suppose that I have an Entity Framework model with an "Order" entity that has an "OrderLines" collection. The "OrderLines" collection is ostensibly a collection of OrderLine objects, but I am using inheritance here, so the actual type of an object in the collection is g...

LINQ One to Many, 3 levels Deep Question

I am trying to figure out what I am doing wrong in the below LINQ statement. It doesn't like the third SELECT. It finds tblAddresse.tblAdminCounty in Intelisense when I am typing the query but when I type the SELECT after it it freaks. Does it have to do with how tblAddress and tblAdminCounty are related? I would have thought that ...

LINQ, Should I JOIN or use nested SELECT NEW's

I have to below 2 LINQ statements. They both return (seemingly) the same result set. Can anyone explain to me why I should use one way versus the other? Is it as simple as "You say potato, I say potato; you say tomato, I say tomato"? Here are the two flavors of LINQ --> 1) The two lets below are to private Methods that take an ID an...

Using LINQ Contains versus SqlMethods.Like

How do I replicate the following result in my LINQ query without calling in the helper library System.data.Linq.SqlClient? Where SqlMethods.Like(e.POSITION, "%A[FGL]7%") _ I would like this query to be more purely LINQ if possible. ...

What's the neatest way to achieve "MinOrDefault" in Linq?

I'm producing a list of decimal values from a linq expression and I want the minimum non zero value. However it's entirely possible that the linq expression will result in an empty list. This will raise an exception and there is no MinOrDefault to cope with this situation. decimal result = (from Item itm in itemList w...

if statement on a foreach

I notice i do this pattern a lot. Is there a better way to write this? bool hit=false; foreach (var tag in tags) if (tag == sz) { hit = true; break; } if (hit) continue; //tags.add(sz); or whatever i w...

How to flatten a type (not an enumerable) through Linq?

All of the examples for SelectMany I see are flattening arrays of arrays and so on. I have a different angle on this question. I have an array of a type, and I want to extract that type's contents into a stream. Here's my example code: public class MyClass { class Foo { public int X, Y; } static IEnumerable<int...

Is there any way to negate a Predicate?

I want to do something like this: List<SomeClass> list1 = ... List<SomeClass> list2 = ... Predicate<SomeClass> condition = ... ... list2.RemoveAll (!condition); ... list2.AddRange (list1.FindAll (condition)); However, this results in a compiler error, as ! can't be applied to Predicate<SomeClass>. Is there any way to do this? ...

Linq to DataSet - Handling Null Values

I have a requirement to convert LINQ to DataTable. I stole the following Extension Method from StackOverflow: public static DataTable ToDataTable<T>(this IEnumerable<T> items) { var tb = new DataTable(typeof(T).Name); PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public ...

Handling Null in WriteXml

For coonverting Linq to DataTable I am using the following Extension Method(Taken from Stackoverflow) Linq to DataTable public static DataTable ToDataTable<T>(this IEnumerable<T> items) { DataTable table = new DataTable(typeof(T).Name); PropertyInfo[] props = typeof(T).GetProperties(BindingFlags.Public | ...

Error, method not supported by LINQ to Entities

Why I am getting this error: The method 'Single' is not supported by LINQ to Entities. Consider using the method 'First' instead. public ActionResult Details(int id) Line 27: { var result = (from d in _db.MovieSet Line 29: where d.Id == id Line 30: select d).Single(); // ...

Linq to Xml Convert a list

I am having trouble wrapping my mind around how to do this in linq. How can i convert this: <mytags> <tag1>hello</tag1> <tag2>hello</tag2> <tag1>MissingTag</tag1> <tag1>Goodbye</tag1> <tag2>Goodbye</tag2> </mytags> to this List<MyObject> public class MyObject { public tag1; public tag2; } ...

List<T> Ordering

I have an issue, I am allowing a user to select the criterea for ordering a List Lets say my list is called List<Cars> AllCars = new List<Cars>; allCars = //call the database and get all the cars I now want to order this list allCars.orderBy(registrationDate) I understand the above doesn't work but i haven't anyidea what i shoul...

LINQ, repository pattern and many-to-many relations

Hello, I've a problem with saving changes to database, I'm using LINQ2SQL mapping. I've implemented M:M relation (User <= UserRole => Role) based on tutorial: http://www.codeproject.com/KB/linq/linqtutorial2.aspx#premain25 Everything works fine when I'm using one class which is inherits from DataContext and is responsible for all of m...

Where is IQueryable in the .NET Compact Framework?

I have started to develop a repository using LINQ to SQL against SQL CE in a Windows project. This works fine. However, when I went to port the code over to .NET CF for a Windows Mobile application, the IQueryable does not appear to exist. What is the best way to make this work across Mobile and Desktop? ...

Pass a property of a Linq entity in a method to set and get result

I'm trying to pass in a property of a Linq entity to be used by my method. I can easily pass a property to be queried Func<Entities.MyEntity, ResultType> GetProperty = ent => ent.Property; However this returns ResultType and cannot be used to set the property. I thought about using reflection to get a propertyInfo, but this will le...

IQueryable to string[] array?

Hello I have this piece of code: public string[] GetUsergroupRoles(string username) { var qry = from ug in _entities.Usergroups from r in _entities.Roles from u in _entities.Users where u.Username == username group r by new { ...