linq

Dealing with a null datetime element within xml using linq

HI I have an example document that looks like <ItemEntry> <PurchaseDate>2010-03-18T20:36:32.81108+13:00</PurchaseDate> <StoreGUID>0a0324ad-5f99-486a-a2d0-870bc6991e9f</StoreGUID> <ExpiryDate /> <CardID>111111</CardID> <PurchaseAmount>0</PurchaseAmount> <RedeemedAmount /> <EntryType>1</EntryType> <RedeemedDate /> <SalesAssistantID>0</Sa...

Does Distinct() preserve always take the first element in the list

Would int[] nums = { 2, 3, 3, 4, 2, 1, 6, 7, 10 }; var distinct = nums.Distinct(); always return 2, 3, 4, 1, 6, 7, 10 in that order? ...

C# Check for missing number in sequence

I have an List<int> which contains 1,2,4,7,9 for example. I have a range from 0 to 10. Is there a way to determine what numbers are missing in that sequence? I thought LINQ might provide an option but I can't see one In the real world my List could contain 100,000 items so performance is key ...

C# Using Enumerable Range and Except with custom class to determine missing sequence number

I have a List<MyClass> The class is like this: private class MyClass { public string Name{ get; set; } public int SequenceNumber { get; set; } } I want to work out what Sequence numbers might be missing. I can see how to do this here however because this is a class I am unsure what to do? ...

Advice on Linq to SQL mapping object design

I hope the title and following text are clear, I'm not very familiar with the correct terms so please correct me if I get anything wrong. I'm using Linq ORM for the first time and am wondering how to address the following. Say I have two DB tables: User ---- Id Name Phone ----- Id UserId Model The Linq code generator produces a bun...

Accessing Linq Values in ViewData

I'm having trouble accessing the id, area and theme values in my ViewData. They are being set in my action filter but when I get to the Site.Master I don't have access to them. Any help or advice would be great. ActionFilter public override void OnActionExecuting(ActionExecutingContext filterContext) { int SectionID = Convert.ToI...

what is the difference between LINQ and ADO.net

what is the difference between LINQ and ADO.net ...

What is the leading LINQ for JavaScript library?

I'm looking for a JavaScript library that will allow me to query complex JSON objects using a LINQ-like syntax. A quick search found a couple of promising options that look they might offer what I need: LINQ to JavaScript and jLinq Does any one have any experience using them? What are some pros and cons? Is the performance comparable...

How To Work With SQL Database Added As Item In Visual Studio 2008?

If I'm letting Visual Studio take care of adding an SQL Server database to an existing project, it adds the connection string to app.config. How can I use use THAT connection string to make my own connections and datasets? ...

VB.NET equivalent to C# var keyword

Is there a VB.NET equivalent to the C# var keyword? I would like to use it to retrieve the result of a LINQ query. ...

error with linq join

I have this linq query: var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts on new {s.ID, settings.GruppoSegreteria} equals new {h.USR_UtentiReference,h.ID_Gruppo} select s; that has this problem: The type of one of the expressions in the join clause is incorrect. Type infere...

Linq - how does it work??

Hey, I have just been looking into Linq with ASP.Net. It is very neat indeed. I was just wondering - how do all the classes get populated? I mean in ASP.Net, suppose you have a Linq file called Catalogue, and you then use a For loop to loop through Catalogue.Products and print each Product name. How do the details get stored? Does it ju...

Linq: Why won't Group By work when Querying DataSets?

While playing with Linq Group By statements using both DataSet and Linq-to-Sql DataContext, I get different results with the following VB.NET 10 code: #If IS_DS = True Then Dim myData = GetOrdersDS #Else Dim myData = GetNwDataContext #End If Dim MyList = From o In myData.Orders _ Join od In myData.Order_Details On o....

linq selecting into custom object

what is wrong with such code public List<SearchItem> Search(string find) { return (from i in _dataContext.News where i.Text.Contains(find) select new SearchItem { ControllerAction = "test", id = i.Id.ToString(), LinkText = "test" }).ToList(); } public struct SearchItem { public string Controll...

How to write a let clause using the dot notation style

Using the query expression style, the let clause can be easily written. My question is how to use the dot notation style to write a let clause. ...

.Except<T> is throwing an Exception

I have the following code: Public Shared Function GetAvailableManufacturers() As List(Of Manufacturer) 'first get all the live orders and extract their mfrs' Dim sos As List(Of OrderForm) = GetFormsByStatus(StockStatus.Building) Dim unavailableMfrs As New List(Of Manufacturer) For Each so As StockingOrder In sos ...

Tricky string transformation (hopefully) in LINQ

I'm hoping for a concise way to perform the following transformation. I want to transform song lyrics. The input will look something like this: Verse 1 lyrics line 1 Verse 1 lyrics line 2 Verse 1 lyrics line 3 Verse 1 lyrics line 4 Verse 2 lyrics line 1 Verse 2 lyrics line 2 Verse 2 lyrics line 3 Verse 2 lyrics line 4 And I want to...

Need help Linq query join + count + group by

I have two table First table BID Town 1 ABC 2 ABC2 3 ABC Second Table PID BID AmountFirst AmountSecond AmountThird Minority 1 1 1000 1000 1000 SC 2 2 2000 1000 2000 ST 3 3 1000 1000 1000 SC BID is foreign key in Second table. I want sum AmountFirst...

Is looping through the entityreference the correct way?

I want to get all users that have a specific role to a list of usernames. Is using .Include to include all the users, and going through the UsersReference the best way to loop through all the users that are associated with the role? I noticed I could not do a foreach(User user in role.Users) but UsersReference seem to work, but is that...

Membership.GetUser() within TransactionScope throws TransactionPromotionException

The following code throws a TransactionAbortedException with message "The transaction has aborted" and an inner TransactionPromotionException with message "Failure while attempting to promote transaction": using ( TransactionScope transactionScope = new TransactionScope() ) { try { using ( MyDataConte...