linq

only update 1 column with linq

Hi, I'm using linq to retrieve a row from a table in the database. Now I only update 1 column. Then I update it back into the database. this goes well, except for the times any of the other fields is changed by another process/thread/user In that case I get an exception (optimistic concurrency), telling me to look out, values have been...

Can't Insert new record from WPF Datagrid via LINQ-to-SQL

Ok, what I'm doing is (I think) rather simple. I have a LINQ-to-SQL data context set up and one of the tables is Users. In the designer, it shows the class as "User" with the source as "dbo.Users". It's access is Public, and I can reach the database to retrieve and update just fine. The class is set to "Use Runtime" for the I/D/U ope...

Insert row into table that has FK obtained from another table - linq -c#

I have 2 tables, Clients and ClientInterests. The PK/FK being ClientID of type GUID This is my Linq, where I want to insert into the ClientIneterests table ClientInterestRegistration clientRegisteration = new ClientInterestRegistration { ClientID = (from v in DB.Clients where v.Email.Equals(EmailAddress) ...

SQL Server: Access Fulltext Index via LINQ

Hello, is there any way to instruct LINQ to run a Fulltext Index Query (such as CONTAINS)? Any text search queries LINQ is currently building for me are only ending up with the LIKE operator. Do I need to create a stored procedure for this? An example would be fantastic! Thank you! ...

LINQ to SQL: Concurrency resolution

Given this LINQ to SQL: using (var db = Database.Context) { var root = (from post in db.Post where post.Id == rootPostId select post).Single(); root.LastActivityUtc = DateTime.UtcNow; db.SubmitChanges(); } What will happen if the same record is concurrently being changed by another call to...

LINQ to SQL delete producing "Specified cast is not valid" error

I've got a painfully simple table that is giving me a "Specified cast is not valid" error when I try to delete one or more rows. The table has two columns, an "id" as the primary key (INT), and a "name" (VARCHAR(20)), which maps to a String in the LINQ to SQL dbml file. Both of these statements produce the error: dc.DeleteOnSubmit(dc.My...

Convert or map a class instance to a list of another one by using Lambda or LINQ?

I have the following two classes: class MyData { public List<string> PropertyList { get; private set;} public string PropertyB { get; set; } public string PropertyC { get; set; } } class MyData2 { public string PropertyA { get; set;} public string PropertyB { get; set; } public string PropertyC { get; set; } } If I have a...

Why doesn't IEnumerable<T>.Max constrain T to be IComparable?

If one calls the .Max() extension method on an IEnumerable<T>, and the objects within do not implement IComparable, one gets System.ArgumentException: At least one object must implement IComparable. Why don't Max and similar methods constrain T to implement IComparable, so that this problem can be caught at compile time instead of at ru...

LINQ "zip" in String Array

I have two arrays as below, String[] title = { "One","Two","three","Four"}; String[] user = { "rob","","john",""}; I need to filter the above array so that I the User value is not Empty. Final Output should be something link { "One:rob","three:john" } How can I achive this using LINQ ...

Linq join several arrays

I have List<Product[]> and I need to join them in Product[] from it. ...

LINQ Dynamic Expression API, predicate with DBNull.Value comparison

I have an issue using the Dynamic Expression API. I cannot seem to compare a DataTable field against DBNull.Value. The API is supposed to be able to "support static field or static property access. Any public field or property can be accessed.". However given the following query: var whatever = table1.AsEnumerable() ...

Convert or map a list of class to another list of class by using Lambda or LINQ?

The question and answer of converting a class to another list of class is cool. How about to convert a list of MyData to another list of MyData2? For example: List<MyData> list1 = new List<MyData>(); // somewhere list1 is populated List<MyData2> list2; // Now I need list2 from list1. How to use similar LINQ or Lambda to get list2 = ... ...

Will there be IQueryable-like additions to IObservable? (.NET Rx)

The new IObservable/IObserver frameworks in the System.Reactive library coming in .NET 4.0 are very exciting (see this and this link). It may be too early to speculate, but will there also be a (for lack of a better term) IQueryable-like framework built for these new interfaces as well? One particular use case would be to assist in pre...

How can I determine if an entity collection contains one of several possible values?

With the .Net Entity Framework and Linq, I'm having a problem finding the best (i.e. easiest to read/understand) way to implement a search for whether or not an entity collection contains any of several possible values. Consider a basic membership/roles implementation, where User has a Roles collection. What would be the "best" way to ...

Non-Generated Property in LINQ to SQL insert behavior

Is it possible to force the LINQ to SQL designer behavior editor to recognize properties on table entities that have not been generated by the designer itself? That is - I want to pass a custom property (defined in my own partial class) as a parameter to a stored procedure. I've tried manually specifying the parameter name in the XML (w...

"Hiding" linq classes inside a namespace?

Hi :) Is there any way to make the generated linq classes stay inside a namespace? The reason being that im working on a big project, and there is alot of tables with different names, and i dont want them to be accessable from anywhere in the project, unless we add the namespace.. I know thats already implemented in the entity framewor...

Strange Exception thrown using Dynamic Linq Entity Framework Query

I have a gallery entity framework class,and I'm attempting to use the Dynamic Linq Library posted on ScottGu's blog to query the entity set. The failing line of code reads: return context.Galleries.OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList(); sidx=="Name", and sord=="desc". The Gallery object does have a propert...

How can i find XElement using linq

Hi there. I m working with c#. <Tüberkiloz> <Kod> 1000 </Kod> </Tüberkiloz> <Tifo> <Kod> 1001 </Kod> </Tifo> <Bakteriyel_Endokardit> <Kod> 1002 </Kod> </Bakteriyel_Endokardit> this is my xml. And i wanna take Tifo. I must use "Kod" nodes. e.g XpathSelectelement("Kod").value = 1001 ...

Check if a value is in a collection with LINQ

Hello, I have a class "Employee", this has an IList<> of "TypeOfWork". public class Employee { public virtual IList<TypeOfWork> TypeOfWorks { get; set; } } public class TypeOfWork { public virtual Customer Customer { get; set; } public virtual Guid Id { get; set; } public virtual string Name{ get; set; } public vi...

What is the Efficiency and Performance of LINQ and Lambda Expression in .Net?

I have used .Net 3.5 and VS 2008 for more than a month. Like most .Net developers, I have evolved from years experience in .Net 1.0 & 2.0 and VS 2005. Just recently, I discovered the simplicity and power of LINQ and Lamda Expressions, as in my recent questions such as Find an item in list by LINQ, Convert or map a class instance to a lis...