linq

Linq search result by closest match

I have an ObservableCollection, which holds a Person object. I have a search feature in my application, and would like to display the most relevant results at the top. What would be the most efficient way of doing this? My current search method simply calls the contains method: var results = (from s in userList where s.N...

Elegant solution - delete and re-add related child list as a batch with Linq-To-SQL

I've got a table called ItemAttributes that is going to have many records for any given parent item record. The user interface allows the user to add/remove ItemAttributes in batch mode and click save one time. So in the case of update I need to do one of two things. Delete all prior ItemAttributes and add all resulting items the us...

NHibernate - LINQ Limitations

Hi, i've been using Nhibernate with LINQ a fair bit now and i have a few issues. Say i have the following entities: public class User { public virtual int UserID { get; set; } public virtual bool IsActive { get; set; } public virtual bool SomeField { get { return 0; } } public virtual DateTime DateRegistered { get; set;...

How can I use DataContext class to establish a connection to Oracle Database?

Is it possible to use the DataContext class to connect to an Oracle DB? I am reading some examples on MSDN I need an example where the context is used to connect to Oracle. ...

Question About Querying Linq Results

When you query existing linq results, it's like they're stuck a layer deeper than the original result. Let me explain what I mean by this. In the example below, after getting ResultSorted, to get to the data therein, you have to use RowSorted.All.TableData.Field, but in the unsorted Result, you could just do Row.TableData.Field. In ...

LINQ Doesn't create DBML file correctly when updating a stored procedure

It instead creates it with a return value of int and doesn't create the spGetRowsFromTableRESULT object, which causes major problems in my application. Previous solutions in the past have been to remove the stored procedure from the DBML file, re-compile (commenting-out any references) and re-adding it. Please if anyone has any informa...

Comparing 2 Dictionary<string, string> Instances

I want to compare the contents of two Dictionary<string, string> instances regardless of the order of the items they contain. SequenceEquals also compares the order, so I first order the dictionaries by key and then call SequenceEquals. Is there a method that I can use instead of SequenceEquals that will only compare the contents? I...

Dynamic LINQ GroupBy Multiple Columns

I need to translate the following LINQ query to Dynamic LINQ that accepts several grouping columns based on user input. Basically I have a bunch of dropdownlists that apply groupings and I don't want to enumerate every combination of groupings. If Dynamic LINQ fails, I may have to construct a SQL query manually, and nobody wants that. ...

Request Genres by MovieId using LINQ to Netflix OData

I am trying to create a LINQ query to return genres by movieid. The LINQ works in LINQPAD4. Can someone help me with the proper syntax? I am getting the following errors: Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IQueryable'. An explicit conversion exists (are you missing a cast?) and Cannot imp...

LINQ Select Distinct while ignoring the XML field

Hello, I have a complex LINQ query (using LINQ 2 EF) that can return duplicate results and I'm thus using the .Distinct() method to avoid duplicates. Here's the skeleton: var subQuery1 = // one query... var subQuery2 = // another query... var result = subQuery1.Distinct().Union( subQuery2.Distinct() ).ToArray(); Each of the sub que...

C# Linq Union Returning Null

I have a simple linq query that unionizes two tables that implement the same interface. For this example, lets say IAnimal. var q = (from d in db.Dogs where d.AnimalID = PetID select d.Name) .Union (from c in db.Cats where c.AnimalID = PetID select c.Name) So if the dog portion has ...

simple way to update IEnumerable objects using LINQ

Hi, Assume i have a business object like this, class Employee { public string name; public int id; public string desgination; public int grade; } List<Employee> lstEmp = new List<Employee>() { new Employee() { name="A",desgination="SE",id=1}, new Employee() ...

linq: grandparent - parent - children query

Hi, I have an entity model and I've been looking to write a linq query that returns counts of children and parents for each grandparent. I need to output 3 columns: Name of Grandparent | Count of Children | Count of Grandchildren protected void Page_Load(object sender, EventArgs e) { using (FamilyModel.TheConn myEntities = new Fa...

How to perform a Linq "First" query on a strongly-typed DataTable object ?

Hi, I'm trying to perform a simple Linq "find first" query on a typed DataTable, but cannot seem to get the syntax correct. (If I don't use typed data table/row objects, things work just fine.) I have this... class Program { static void Main(string[] args) { MyDataTable table = new MyDataTable("table"); table.Rows.Add(...

Order by in Linq

how can i show null or empty fields in last by apply Orderby: here is my code. Var movies = _db.Movies.Orderby(c => c.Category).ThenBy(n => n.Name) ...

How to dynamically build and return a linq predicate based on user input

Getting a bit stuck on this. Basically I have a method that I want to return a predicate expression that I can use as a Where condition. I think what I need to do is similar to this: http://msdn.microsoft.com/en-us/library/bb882637.aspx but I'm a bit stuck as to what I need to do. Method: private static Expression<Func<Conference, bo...

Read text file word-by-word using LINQ

Hey, I am learning LINQ, and I want to read a text file (let's say an e-book) word by word using LINQ. This is wht I could come up with: static void Main() { string[] content = File.ReadAllLines("text.txt"); var query = (from c in content select content); foreach ...

How to optimize and pre-compile this LINQ expression?

Given the following input against 60% toleration "STACKOVERflow is a quesTions and ANSwers weBSITE" I expect the following output // Extra spaces just to show %s // 69% 50% 100% 22%! 33% 42% 14% "Stackoverflow Is A QuesTions And ANSwers Website" Questions and Answers have uppercase characters but they rep...

Dynamic Linq Select concatenation

I have a dynamic select statement thus: "new(PurchaseOrderID as ID_PK, PContractNo + GoodsSupplier.AssociatedTo.DisplayName as Search_Results)" As can be seen I wish to concatenate the 'PContractNo' and 'GoodsSupplier.AssociatedTo.DisplayName' fields into one returned field named 'Search_Results'. It is important that these two fields ...

How to access a particular data in LINQ query result ?

I know, this is very simple for you guys. Please consider the following code: string[] str = { "dataReader", "dataTable", "gridView", "textBox", "bool" }; var s = from n in str where n.StartsWith("data") select n; foreach (var x in s) { Consol...