linq

LINQ queries with many-to-many tables in Entity Data Model

I'm trying to use LINQ to query the following Entity Data Model based on this db model I'd like to be able to pull a list of products based on ProductFacets.FacetTypeId. Normally, I'd use joins and this wouldn't be a problem but I don't quite understand how to query many-to-many tables under the Entity DataModel. This is an exampl...

Subsonic SimpleRepository NullReferenceException in Contains with cast

Hi, I have a problem with this subsonic3.0.0.4 find statement: rep = new SimpleRepository(" ... "); rep.Find<MyObject>( x => x.Code.ToString("00000").Contains("023") ); The Code field is Long value and the sql query that I need is: *SELECT * FROM ... WHERE convert(varchar, Code) LIKE '%023%'* When I execute it, NullReferenceExceptio...

Assigning max values from a dictionary

I need to assign values from a small dictionary collection (10 items) to a larger number (about 20 to 30) of dropdownlists in their selected value property. Specifically, I need to take the key of the max value in the dictionary, assign it to the first dropdownlist.selected value. Then take the key of the 2nd highest max value, assign ...

Returning list of properties from a list of objects

I have a list of Tenants (call it TenantList), and it's composed of Tenant objects and they all have an ID property. How can I return an enumerable item composed of their ID properties? ...

Why doesn't the Controls collection provide all of the IEnumerable methods?

I'm not for sure how the ControlCollection of ASP.Net works, so maybe someone can shed some light on this for me. I recently discovered the magic that is extension methods and Linq. Well, I was very sad to find that this isn't valid syntax var c=Controls.Where(x => x.ID=="Some ID").SingleOrDefault(); However from what I can tell, Co...

C# lambda extract a single row string value

Want to extract the text value from a lookup table's column in a db. EL is the entity for my db. Current code : var QTypes = EL.ElogQueryType.Where<ElogQueryType>( eqt=> eqt.ID == queryTypeID); string qType = QTypes.First().QueryType; I get a list when I just pull .Select(... so something is wrong. ...

How to refresh relational property of a LINQ class?

Hi, I have two instances of a program that manipulate same Northwind database. When I add some records to the database from one of the instances (for example adding some orders to Orders table with a customer foreign key John), I can query these new records from the other instance of the program properly. The problem begins when I want t...

Creating objects using LINQ

I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle> <EmployeeStory> <EmployeeStoryHeaderParagraph> <EmployeeHeader>Employee Header 1</EmployeeHeader> <EmployeeParagraphs> <EmployeeParagraph>Employe...

Composite DisplayMember for ComboBox

I need to display multiple pieces of data in a combobox, but I can't figure out how to do it. Here's the code I'm trying to make work: innerBox.DisplayMember = @"t => t.TenantName + ""\t"" + t.Property.PropertyName + ""\t"" + t.RentalUnit.UnitNumber "; But it doesn't work, this does though: innerBox.DisplayMember = @...

C# Super fancy LINQiness

I'm trying to write a dynamic sort of command line processor where I have a dictionary with keys being possible parameters, and the member being an Action where the string is the text between the parameters passed on the command line. Want to be able to add parameters just by adding the params array, and writing the action in the diction...

Can Someone Explain This MSDN Code To Me In English?

This is concurrency related. So the SubmitChanges() fails, and a ChangeConflictException is thrown. For each ObjectChangeConflict in db.ChangeConflicts, its Resolve is set to RefreshMode.OverwriteCurrentValues? What does this mean? http://msdn.microsoft.com/en-us/library/bb399354.aspx Northwnd db = new Northwnd("..."); try { db....

Can joins be used when getting objects from a LINQ DataContext?

I'm using LINQ and a DataContext to return a collection of objects from a SQL Server table. The table is named "Widgets" and the corresponding C# class I'm using is shown below. The Widgets table contains a Name column, and a TypeID column which is a foreign key to another table of widget types. [Table(Name = "Widgets")] public Class Wi...

How to Translate this LINQ Query to use Lambda Expressions Instead?

i want this bellow syntax write by useing the lamda expression from p in this.Context.tblUserInfos where p.Status == 1 select new {p.UserID,p.UserName,p.tblUserType.UserType }; suppose i write this.Context.tblUserInfos.Where(p => p.Status == 1); How to write the above syntax by using the => operat...

not able to use CopyToDataTable in linq for returning dataset

how to return a dataset from linq in .net 3.5? I have seen in some sites that CopyToDataTable method is used but I am not able to use that methos as I cannot find System.data.datatableextensions reference in the ref list. Please help me out. Thanks and regards, veena ...

Copying Result of Linq into DataTable

What changes do i need to make so as to reduce of doing this task with fewer lines and better approach. DataTable dtStatusMsgs; var statusList = ( from items in dtInputTable.AsEnumerable() where items.Field<int>("DepartmentId") == deptId select new { ...

Database advice needed: porting VB6/ADO/JET app to VB.NET

I need to update (well, rewrite really) a SMALL VB6 application which uses ADO to access a JET database, to a vb.net app in Visual Studio 2008. My research suggests that I should use LINQ, but it doesn't seem to be possible to connect to JET. If JET is now deprecated, what should I use? Or should I use ADO.NET without LINQ? Please don'...

How can I update the record in sharepoint 2010 using linq.

Hi, I am unable to update the record in SharePoint 2010 using new linq feature. follwoing in my code please review it. AbsentTrackingSystemEntitiesDataContext ctx = new AbsentTrackingSystemEntitiesDataContext(spWeb.Url); ctx.ObjectTrackingEnabled = true; HolidaysItem Holidayobj = GetHolidays(HolidayID,...

how can i find repeated Customer detail in target table?

i have repeated data in Target class list new TargetClass{ TID=102, ID=2, Adress="afff", Zip="222"}, new TargetClass{ TID=103, ID=2, Adress="bfff", Zip="222"}, i need reated ID's Data from li2 how can i do that? for example ıD=2 is repeated like ID = 3i want to take 2,3 (ID) detail in li2? How can i do that with linq? ...

Linq 2 SQL Syntax Help

I am almost done converting a MySQL app to Linq2SQL but struggling to get my head round this last SQL query SELECT a.URL, b.URL AS DuplicateURL FROM Pages a INNER JOIN Pages b ON a.MetaDescription = b.MetaDescription AND a.PageID <> b.PageID WHERE a.DomainID = @reportid AND b.DomainID = @reportid AND LENGTH(TRIM(a...

LINQ select items from set A which are not in set B.

I would like to perform an Except operation on set of items. Code is like this: IEnumerable<DataGridViewColumn> dgvColumns = dataGridView.Columns.OfType<DataGridViewColumn>(); IEnumerable<DataColumn> dsColumns = dataSet.Tables[0].Columns.OfType<DataColumn>(); Now, how to select Columns from dataSet.Tables[0] which are not in dgvColum...