linq

How are attached properties useful in LINQ?

I got this question during an interview in the past and never really dug into in, but I've put some thought into it lately and I can't come up with a good answer. When I think of attached properties my mind goes straight to UI related concepts - what benefits could be had in using attached properties with LINQ? I'm starting to think th...

LINQ - group specific types of classes

This question is similar to http://stackoverflow.com/questions/2835192/linq-group-one-type-of-item but handled in a more generic way. I have a List that has various derived classes. I may have something like this: List<BaseClass> list = new List<BaseClass>() { new Class1(1), new Class2(1), new Class1(2), new Class3(1), new Cl...

return a single list property List in Linq

I am having an issue here i have a list this.Ddown having 3 properties i want to write a Linq Query to return one of the property lets say i have property a,b,c i want to retutn list(c) how do i do that in linq ...

linq delegate function checking from objects

I am trying to find the list of objects which can be replaced. Class Letter{ int ID; string Name; string AdvCode; int isDeleted; } Class Replacers{ int ID; string MainAdvCode; string ReplacesAdvCode; } example data: Replacers 0 455 400 1 955 400 2 955 455 LettersA 0 pack 455 1 addon 400 LettersB 0 big 955 1 pack 455 LettersC 0...

Eager loading in EF1.0

I have a many-to-many relationship: Application -> Applications_Servers -> Server This is set up in my Entity Data Model and all is well. My problem is that I'd like to eager-load the whole graph of Applications so that I have an IEnumerable<Applications>, each Application member populated with the Servers collection associated by the...

Expression.Default in .NET 3.5

How can I emulate Expression.Default (new in .NET 4.0) in 3.5? Do I need to manually check the expression type and use different code for reference and value types? This is what I'm currently doing, is there a better way? Expression GetDefaultExpression(Type type) { if (type.IsValueType) return Expression.New(type); re...

How to perform group by in LINQ and get a Iqueryable or a Custom Class Object?

Here is my query - var data = Goaldata.GroupBy(c => c.GoalId).ToList(); This returns a Igrouping object and I want an Iqueryable object which I can directly query to get the data while in this case I have to loop through using a foreach() and then get the data. Is there another way to group by in LINQ which returns directly as a list...

how to get cartesian products between database and local sequences in linq?

I saw this similar question here but can't figure out how to use Contains in Cartesian product desired result situation: http://stackoverflow.com/questions/1712105/linq-to-sql-exception-local-sequence-cannot-be-used-in-linq-to-sql-implementatio Let's say I have following: var a = new [] { 1, 4, 7 }; var b = new [] { 2, 5, 8 }; var te...

Ensuring Database Integrity when Adding and Deleting

As I am developing my database, I am working to ensure data integrity. So, for example, a Book should be deleted when its Author is deleted from the database (but not vice-versa), assuming one author. When I setup the foreign-key, I did set up a CASCADE, so I feel like this should happen automatically if I perform a delete from LINQ. ...

LINQDataSource - Query Multiple Tables?

I have a database and I've created a DBML Linq-to-SQL file to represent this database. I've created a new aspx page and dropped a linqdatasource and a formview control onto it. When I configure the linqdatasource it gives me the choice only to select * from one table...but I want to pull from multiple tables. e.g. I have tables like simp...

Entity Date Modelset Generates Errors in Visual Web Developer

I attempted to add a ADO.NET Entity Data Model to my Visual Web Developer 2010 Express project and it generates but returns a whole slew of errors. Why is this generating errors? Here are the main errors: 'Public Property ID As Integer' has multiple definitions with identical signatures. Method 'Onaddress_IDChanging' cannot be declared ...

whats wrong in this LINQ synatx?

Hi, I am trying to convert a SQL query to LINQ. Somehow my count(distinct(x)) logic does not seem to be working correctly. The original SQL is quite efficient(or so i think), but the generated SQL is not even returning the correct result. I am trying to fix this LINQ to do what the original SQL is doing, AND in an efficient way as the o...

dragging and dropping in asp.net?

Hi Guys, I am new to web development, I am coding some ASP.NET, I watched many videos about using LINQ to SQL, I am happy I learned something, but is it the good way of using is: dragging and dropping and that's done??? what are the best practices to use LINQ to access Database ( my database is not only SQL server..MYSQL..) Thanks ...

LINQ thinks I need an extra INNER JOIN, but why?

I have a LINQ query, which for some reason is generating an extra/duplicate INNER JOIN. This is causing the query to not return the expected output. If I manually comment that extra JOIN from the generated SQL, then I get seemingly correct output. Can you detect what I might have done in this LINQ to have caused this extra JOIN? Thanks...

How to map a Stored proc result to an existing DA class

When I use SQLMetal to create the linq version of one of my stored procs it creates a returned class specific to the proc - I want to map the result to an existing DA table class. any ideas? ...

Read from XML > Add to Listview

I have some problems getting the data that i read from XML split into seperate columns. Any help this new C# coder would get would be appreciated. XDocument xmlDoc = XDocument.Load("emails.xml"); var t = from c in xmlDoc.Descendants("dt") select (string)c.Element("name") + (string)c.Element("email");...

Do I have to refresh a LINQ object that represents a view/table row after I do a submitchanges operation that may alter it?

Do I have to refresh a LINQ object that represents a view/table row after I do a submitchanges operation that may alter it? Let's say I have Event _event = new Event { someproperty = "this"; }; DataContext.Events.InsertOnSubmit(_event); DataContext.SubmitChanges(); //some operations _event.someproperty = "that"; DataContext.Submit...

LINQ query checks for null

I have a userList, some users don't have a name (null). If I run the first LINQ query, I got an error saying "object reference not set to an instance of an object" error. var temp = (from a in userList where ((a.name == "john") && (a.name != null)) select a).ToList(); However, if I switch the order by putting ...

Using VirtualMode on a DataGridView when the number of rows/columns isn't known

I need to display an unknown length sequence of dictionaries with unknown keys efficiently in a data grid. This sequence is the result of a potentially slow LINQ query that could contain any number of results. At first I thought that VirtualMode on DataGridView was what I was looking for but it appears that the number of rows and column...

Comparing 2 linq applications: Unexpected result

I drafted 2 ASP.NET applications using LINQ. One connects to MS SQL Server, another to some proprietary memory structure. Both applications work with tables of 3 int fields, having 500 000 records (the memory structure is identical to SQL Server table). The controls used are regular: GridView and ObjectDataSource. In the applications I c...