linq

Grouping in LINQ - simple question

Hi, I'm trying to get a list of the unique values from a field called 'domain' using the query below. Instead of just giving me the values themselves, my dropdown (drpDomain) contains values in this format: {Key = LNAU} etc. All I want to see is the value itself. Am I missing something obvious? Thanks! var domainList = from v in db...

LINQ on System.Object (type known only at runtime using reflection)

I have a simlar requirement where in i have 3 main entities in ADO.NET entity model... I am building a framework wherein basedon incoming XML root element i have to create an instance of specific entity using reflection and set its properties.. But when it comes to child entities.. I am not able to use LINQ queries on it as the type is...

Optimize a LINQ OrderByDescending query

I need to run a LINQ on a generic collection. The current query runs at a really slow pace... var patternsWithMaxLenArray = totalPatterns .Where ( pattern => pattern.Contains(maxLen) && pattern.All(lenInPattern => curQuantities.Keys.Contains(lenInPattern)) && pattern.GroupBy(len => l...

Problem with Linq re-evaluation, skips content.

Now I'm not really sure what the problem here is but it seems that Linq quaries are re-evaluated each iteration wich is a effect I wan't here. However for some reason he skips elements he shouldn't when he does so. Can someone help me understand what's going on here. Here is the Linq-to-XML code: var contents = (from sdt in document.Ma...

Magical Object Database needed with .Net bindings

Hello, Lets assume im writing a program, my program has its own entities and such. And since I'm using an OOP .Net language (C#, but could be F# or Iron Python), my objects have weird OOP traits like inheritance, references to other objects, and hierarchical relationships. Naturally i want to save these all to my God damn database, an...

Building a C# Linq helper

Hi all, I'm trying to build a utility method using Linq that will help me with a common Linq-to-Objects search. I have a PropertyTbl object which has a reference to an Address. I have a IEnumerable<PropertyTbl>. I have written a helper that takes an IEnumerable<Address> and some search criteria returns an IEnumerable<Address> which whe...

Data Access Layer - LINQ-To-SQL and generics. Can I optimize this?

Hi, We are working on improving our DAL which is written in LINQ that talks to the MS SQL database. Our goal is to achieve good re-usability with as little code as possible. LINQ generated files are making a use of generics and reflection to map LINQ generated classes to the SQL objects (tables and views in our case). Please see the e...

What is wrong with this linq query?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ds As DataSet ds = getData() Dim dt As DataTable = ds.Tables(0) Dim gridViewData = From r As DataRow In dt.Rows Select r.Item("foo"), r.Item("bar") GridView1.DataSource = gridViewData GridView1.DataBind() End Sub I j...

LINQ-To-SQL - Is it possible to cache GetTable or serve it from repository?

Hi, I'm running profiler tools on the LINQ-to-SQL data access layer. A lot of the time is spent on GetTable<clsName>() because it's being called each time i CRUD data. Is it possible to cache GetTable<clsName>() for all the tables when the application starts or serve it through some sort of repository where it will be in memory? Th...

How to walk through a SelectListItem Array with Linq - techniques?

Hello, Linq – Newbie question: string[] grades = { "2", "5", "1", "7", "4", "8", "6", "0", "9", "3" }; List<SelectListItem> xValues = new List<SelectListItem>() { new SelectListItem { Selected = true, Text = "Sel...

How to programmatically set label text - Linq To Entities

Hello all. I have to set the label text of a load of differnet labels on a web page based upon user preferences. I have the following code that is place upon the label load event (probably wrong!) string memberid = Session["MemberID"].ToString(); string locationid = Session["LocationID"].ToString(); string user...

Will this XML parsing work?

public Envio(int id) { XDocument xml = XDocument.Parse(LoadFromService(id)); ID = xml.Element("envio") .Element("de").Value; De = xml.Element("envio") .Element("de").Value; Para = xml.Element("envio") .Element("para").Value; Fecha = xml.Element("envio") .Element("fech...

Maintenace tasks under Entity Framework

Hello: After deploying a complete application using Entity Framework (EF) and LINQ, the next things can happen then with the data in a "database which previously was included/mapped to EF in the aplication": Create new tables and include into EF Delete existing tables from the database that were previously included in EF Include new f...

How would I add type specific implementations to linq binary expressions?

I have a fairly simple expression parser that uses the Linq.Expression namespace. Input is something like: (1+1), it finds the left and right constants, and converts the operator char to an ExpressionTypes enum value, creates the appropriate expression, compiles and executes. I'd really like to be able to do string manipulations, (abc+...

Storing binary objects in SQL Server with LINQ

I'm trying to do the same thing as in this question, but am having problems. Can you share with me how you prepared your objects prior to inserting and updating the database? I have a List<myObject> that I want to store as a VarBinary(max) in SQL Server 2008. ...

How do I efficiently compare LINQ expression instances for equality?

Possible Duplicate: Most efficient way to test equality of lambda expressions I was wondering how LINQ expression instances compare for equality. It seems that the expression classes do not implement IEquatable or IComparable or anything alike. Let me give you some background information: I've implemented a caching mechanism ...

CSV to object model mapping

I have a csv file that I want to read in to a List. Here's an example file: Plant,Material,"Density, Lb/ft3",Storage Location FRED,10000477,64.3008,3300 FRED,10000479,62.612,3275 FRED,10000517,90,3550 FRED,10000517,72,3550 FRED,10000532,90,3550 FRED,10000532,72,3550 FRED,10000550,97,3050 I know I can manually read the csv file in and...

C# Linq String[] list minus from String[] list

Hello, Let's say string[] admins = "aron, mike, bob"; string[] users = "mike, katie, sarah"; How can I take the users and strip out anyone from the admins. the result should be "katie, sarah"; (mike was removed) Is there a nice Linq way to do this? ...

linqDataSource bound to dynamic list

Hello, Im trying to create LinqDataSource that will represent data from dynamically created String list and then use it as a datasource to my GridView. List<string> users = RetreiveUsers(); LinqDataSource ds = new LinqDataSource(); and what now ? thanks for help. ...

Entity framework, LINQ or another framework?

We are working on a large C# 3.5 project that requires a centralized database. The database itself is small both in number of tables and in the size of those tables. Typically, the user will pull information from the database and work on a local copy. My assumption is that the local copy will be in XML but this is not a requirement. In s...