linq

how retrieve the value from more than one list at a time using linQ?

i have two list , List A,List B both have same no of values.i like to pass these values as arguments and selecting returning value .here code for(int i=0;i<A.count;i++) { list<int> temp=new list<int>(); temp.add(methodA(A[i],B[i]); } how can i do this using linq.Is it possible to do in .net 3.5 ...

From ... In ... Select in C#

Are there any disadvantages or performance slowdowns related to the use of expressions like from i in Enumerable.Range(1, Math.Min(strTexto.Length, tamMax) + 1) select Tuple.Create(strTexto.Substring(0, i - 1), strTexto.Substring(i - 1)) in C#? Is it preferable to build "hard-coded queries" like foreach (Int32 IntTmp ...

Linq to DataTable not producing Distinct values

Hi, I have a datatable which has been dynamically generated from FoxPro tables using a UNION Select statement. e.g. SELECT * FROM x UNION SELECT * FROM y UNION SELECT * FROM Z ORDER By v_alue1 This produces a datatable with about 100 rows, each containing many fields, one of which is c_olor. From this datatable, I would like to selec...

C#/LINQ: Trying to optimize performance

This is my setup class EditorTabViewModel : TabViewModel { ... public bool CanSave { get; set; }; } ObservableCollection<TabViewModel> _tabs I want to check if there are any tabs in _tabs that are EditorTabViewModel that has property CanSave set to true i did something like ... var tabs = from t in _tabs where ...

Adding A Custom Property To Entity Framework?

I am using the Entity Framework for the first time and want to know if the following is possible - I have generated my classes from the DB, and have one called Category. Obviously it has all my fields in the table (ID, CategoryName, SortOrder etc..) but I want to know if I can add a custom property which is not in the table, but is actu...

How Secure Is Entity Framework?

Just wondering if the entity framework is setup to handle things like SQL injection out the box? Every tutorial I have seen, video, book or blog post. No one mentions security and seems to pass in variables straight into the context with no checks etc... Just wondering what peoples thoughts were on this, and how do you handle this s...

Linq queries on dB and using custom Comparers

Whats the use of using custom comparers in Linq queries? Are they beneficial or are they just an overload on the server. So i am talking about queries like IEnumerable<Class> GetMatch(Class comparerObject) { return Session.Linq<Class>().Where(x=>new StringComparer<Class>().Equals(x,comparerObject)) } and this is how my stringcomp...

Getting an index was out of range exception with NHibernate

Hi all, I'm currently building a web application with MVC and NHibernate. Now when i want to get information out of the database I get an index was out of range exception. The current situation is as follows. I got the mapping files of three database tables: A table to store a group with a one-to-many relationship with subscriberingro...

Inject arguments in LINQ queries

I'm trying to build a complex query with linq. I have a C# method that takes in parameters some arguments: public void function returnAList(string arg1, string arg2, string arg3, string arg4); I put the following code that lets me return a list from my database: List<Person> listOfPersons = this.businessLayer.ReturnPersons(); v...

Linq way to get piecewise difference between element and next element in list

Is there a Linq way of knowing what the next element in the sequence is while iterating? As a concrete example, say I have a list of ints, and I want to calculate the difference between each element and its successor, so for example I would like to be able to write var myList = new List<int>() { 1,3,8,2,10 }; var differences = myList.Se...

Combining 2 LINQ into one call

Hi, I'm using 2 similar LINQ queries to return a result, the only difference is the where clause (&& s.OptIn == "Yes"). Is there a way to execute this with only one query? Instead of having a result of A 2 B 3 and another result of A 1 B 1 I want to have A 2 1 B 3 1 Here's the LINQ: var result = from s in...

Entity Framework and Linq - Comparing DateTime

I have this code public List<CalendarData> GetCalendarData(DateTime day) { List<CalendarData> list = new List<CalendarData>(); using (dataContext = new VTCEntities()) { DateTime test = new DateTime(2010, 10, 20, 17, 45, 0); var data = from z in dataContext.ReservationsSet ...

Problem using linq to concat two collections

Hello, public class A { public bool Selected; public DateTime CreateDate; } I have a collection of A, let call it Coll, i want to do: Coll.Where(a => a.Selected).Concat(Coll.Where(a => !a.Selected) .OrderBy(a => a.CreateDate)) This look great, but the result is the same if i remove the order part, because Linq is generating t...

Help with LINQ distinct()

I have a class called "Orders" that has the property of "City" among others. I am trying to write a LINQ statement that will get all the distinct cities from a list of orders and return them as a list of strings. Here is what I have now. public List<string> GetOrderCities(List<Order> orders) { IEnumerable<string> cities= from o in o...

Left outer join in linq

Hi all, I have the following query but i have no idea on how to do a left outer join on table 1. var query = (from r in table1 join f in table2 on r.ID equals f.ID select new { ...

How to insert a lambda into a Linq declarative query expression

Let's say you have the following code: string encoded="9,8,5,4,9"; // Parse the encoded string into a collection of numbers var nums=from string s in encoded.Split(',') select int.Parse(s); That's easy, but what if I want to apply a lambda expression to s in the select, but still keep this as a declarative query expr...

Arithmetic operations on subqueries using Expression.Subtract(?)

I'm trying to create an expression tree that's similar to performing subqueries like: SELECT (SELECT Sum(Foo) FROM Bar1) - (SELECT Sum(Foo) FROM Bar2)) I'm trying to reuse 2 expression trees that are too complex to repeat. What I have right now is 2 (simplified) expression trees: Expression<Func<Bar, int>> SumBar1 = (bar) => (fr...

can wcf service be loosely decoupled

To start with, I am a newbie in the world of WCF so pardon me if this sounds naive. To my understanding , unlike ASP.NET based websites which use ADO.NET to communicate to the database, a silverlight based app always needs a WCF or RIA services to communicate to DB. We know that ASP.NET websites are not tightly coupled to the database ...

LINQ double left join

I've got a students class with a name, a blogEntries class with a student name and entry title, and a blogAssignments class with an assignment name. I'd like to show ALL students and alongside them the blogEntries they created whose title matches the blogAssignments.assignmentName. I've got the following LINQ query but I can't figure o...

dataset to linq editor (visually create linq query - like vlinq)

Hello, I am interested in creating a visual linq editor (like provided in sql server management studio). which i want to use in my application to give end user the ability to create linq queries on dataset. I tried to understand VLINQ, but i am unable to understand, how can i use it as a starting point. Can someone please guide me or poi...