linq

In generating a Linq to SQL class, how can I define a complex relationship?

I have two views: one is a normal view built from one table with an integer ID and other columns for the record (let's call it View1). I have another View (View2), which has an integer ID column and a second column named "table" (type: varchar). That second column contains the name of the table to which the ID column is related: So, i...

nHibernate Linq join support; The method Join is not implemented

I am using the latest nHibernate.Linq 2.1.2. But if I use join in my linq query I will get run time error "The method Join is not implemented". Could someone tell me if join is supported by nHibernate.Linq and if it is supported what is the cause of this error? ...

Combining 2 lists and and remove duplicates .Output in a third list .My attempts do not work

I always seem to have a problem when I need to compare 2 list and produce a 3rd list which include all unique items.I need to perform this quite often. Attempt to reproduce the issue with a noddy example. Am I missing something? Thanks for any suggestions The wanted result Name= Jo1 Surname= Bloggs1 Category= Account Name= Jo2 ...

Reading Xml file using LINQ in C#

I have a list of String List<String> lst=new List<String>{"A","B","C"} And an xml file like <Root> <ChildList> <Childs> <Child Name="a1" Val="A"/> <Child Name="a2" val="A"/> <Child Name="b1" val="B"/> </Childs> </ChildList> </Root> i need to read contets of the xml file and add to a dictionary ...

using if else with LINQ Where

I want to generate dynamic query to check manage the where clause with number of parameters available...if some parameter is null i don't want to include it in the where clause var test = from p in _db.test where if(str1 != null){p.test == str} else i dnt wanna check p.test I have around 14 parameters for the where clause ...

What type of optimizations does LINQ perform at the compiler level?

Now that LINQ is such an integral part of .NET, are their optimizations at the compiler level that would use the optimal path to get results? For example, imagine you had an array of integers and wanted to get the lowest value. You could do this without LINQ using a foreach, but it's certainly easier to use the Min function in LINQ. O...

If condition in LINQ Where clause.................

Can I use if clause with Linq where? ...

Calculate difference from previous item with LINQ

I'm trying to prepare data for a graph using LINQ. The problem that i cant solve is how to calculate the "difference to previous. the result I expect is ID= 1, Date= Now, DiffToPrev= 0; ID= 1, Date= Now+1, DiffToPrev= 3; ID= 1, Date= Now+2, DiffToPrev= 7; ID= 1, Date= Now+3, DiffToPrev= -6; etc... Can You help me create suc...

LINQ query OrderBy doesn't work

_db.InstellingAdressens .Where(l => l.GEMEENTE.Contains(gem_query)) .OrderBy(q => q.GEMEENTE) .Select(q => q.GEMEENTE) .Distinct(); this is the query. it returns a List<string> but the strings are not ordered at all. Why does the OrderBy have no effect? and how to fix it? ...

LINQ Find non overlapping audit records by date

I have an audit table which stores audit rows for a long running process at an individual task level in SQL Server. auditId int, TaskName nvarchar(255), StartTime datetime, EndTime (datetime, null), Status (nvarchar(255), null) The process contains parent and child steps and each step is logged to the audit table. A task may or ma...

Reading Xml file contents to a class instance in C#

i have a class like class CXmlData { String Data1=""; String Data2=""; List<String> lst=new List<String>() } and a Dictionary Dictionary<String,CXmlData> dict=new Dictionary<String,CXmlData>(); The xml file is having the following structure <Root> <ChildList> <Children> <Chil...

LINQ to XML generates \r\n between tags?

Hello, I am generating a XElement having this structure: <TestNames>\r\n <Test>YA</Test>\r\n <Test>YO</Test>\r\n </TestNames> How do I get rid of the whitespaces and \r\n in a non-hack way :) Update: XElement testsXmlDocument= new XElement("TestNames"); foreach (string test in selectedTests) testsXmlDocumen...

How to cast INT32 to INT during a SQL select through a LINQ data context?

Hi, I have the following statement: someList = dc.ExecuteQuery<MyCustomType>(@"Select Id As ProductId, Name From ivProduct").ToList(); Id in the database is stored as int32, when my Id property of MyCustomType is INT. Is there a way to cast that int32 to int during a select? Thank you ...

web.config app.config and connection stringq linq

Hi, I have solution which has webSite and Core projects. In Core I have all model using LINQ. I there use app.Config to set paths to database in connection string used by my model. Then I use this in my website. Now I would like to have possibility that after deploying website on the iis to change that connections strings. Before Lin...

What causes this Member AutoSync failure?

I have this table: create table dbo.NotificationsIn ( NotificationID varchar(18) primary key, ArrivalTime datetime not null default getdate() ) I insert to it like this: public void InsertNotification(NotificationsIn notification) { db.NotificationsIns.InsertOnSubmit(notification); db.SubmitChanges(); } where db is ...

linq query to get monthly expenses in vb.net

I have a collection of order objects (properties - date, amount and vendor). I need to prepare a report showing spend by vendor by month since 01/01/2009. How can i get the results using LINQ? ...

What to return from my linq to entities query

So I have a data access class library I make a linq to entities call I end up with a single row that has my TableData object. What should I return back from my class library method? I thought it would be cool to return back the TableData object, but I see that if you make changes to it and call a save that it actually updates the dat...

Testing Linq to Entities Queries

What is the best way to do this? Typically when I create a Query in SQL I create it in the designer of visual studio and I run it multiple times to see my results.... Is there such a thing for Linq-to-Entities? ...

Returning null exception on linq statement

There's probably a very simple reason for this, but when hydrating an object I'm keep getting a "value cannot be null" exception: public class MyObject { public MyObject() { } public virtual IList<MemberObject> MemberObjects { get; protected set; } [JsonProperty] public virtual SubObject LastMemberObject...

C# Linq XML pull out nodes from document

Hi I’m trying to use Linq XML to select a number of nodes and the children but getting terrible confused! In the example XML below I need to pull out all the <MostWanted> and all the Wanted with their child nodes but without the other nodes in between the Mostwanted and Wanted nodes. This because each MostWanted can be followed by any ...