linq-to-sql

How to query Anonymous Type collection?

How do you query a collection which is populated/created with select new? I have this BindingSource: this.bindingSource.DataSource = from row in db.Table select new { name = row.Name + row.Num.ToString() }; I'd like to query it like I do with other BindingSources: var query = from row in (IEnumerable<Table>)a...

LINQ to SQL: is there a complete list of supported IQueryable extension methods?

I'm looking for such list for LINQ to SQL. Ideally, I'd like to have a list of other supported methods (or members - e.g. constructors), e.g. for DateTime type. ...

Inserting a new object into L2S table and databinding to it prior to SubmitChanges() in WPF

Hi, I'm just getting started with Linq-to-SQL and data binding in WPF, most of which works like a dream so far! I've got (what I though was) a common scenario: a) Query list of records from a table via datacontext and bind to the current user control this.DataContext = db.ClientTypes; b) Have the user see a bound ListView and some ...

Linq2sql and WCF, getting access to tables

Hi I'm having some difficulties while using linq2sql and wcf. Let suppose I have three tables: Reports, Tasks and Types. Tasks references Reports (one Report can have unlimited number of tasks), and Reports references Types (Report is of some type, e.g. BugReport, ChangeRequest and something like that). Now I want to get by WCF all R...

Why does my LINQ to SQL query fail the first time ("Row Not Found or Changed") and succeed the second time?

I'm using LINQ to SQL in ASP.NET MVC. I wrote some new code to update Orders in our system, and as far as I can tell it's exactly like a hundred other similar pieces of code I've written (grab the object, update some fields, submit changes). This time though, when I try to run the update, I get a "Row not found or changed" LINQ excepti...

String.StartsWith not working with tilde ("~") characters LINQ to SQL?

For some reason, my call to IEnumerable.Where() using String.StartsWith() appears to be giving different results depending on whether it's being used in LINQ-to-SQL or standard LINQ (-to-objects). If I add in a call to ToList() on what's otherwise the same call, I get different results back: var withToList = MyDataContext.MyEntities.ToL...

Linq to Sql query with multiple aggregations

Hi, Given a simple schema e.g. PurchaseOrders { OrderId, Total, LineItemCount }, I want to generate a simple query for some simple stats like below: select sum(lineitemcount) as totalitems, sum(total) as totalsales from purchaseorders However in Linq to Sql I am struggling to get this into one query. At the moment I have this: deci...

Linq-to-Sql: Use LinqDataSource to programmatically retrieve data

I'm using a LinqDataSource to populate a basic GridView in ASP.NET. The user has the ability to filter the results, so I use a few WhereParameters and the Where within the LinqDataSource. My client has requested an option to export the filtered results to a file. Easy enough to pipe the data into a file, but I would prefer not to rewrit...

Linq Working with DataContext

1) I wish to clarify some doubts on collections. SampleDBDataContext PersonDB = new SampleDBDataContext(""); Table<Person> p=PersonDB.GetTable<Person>(); IEnumerable<Person> per = PersonDB.GetTable<Person>(); IQueryable<Person> qry = PersonDB.Persons.Select(c => c); what are the differences between using Table<Person>,IEnumerable<Pers...

My Linq to SQL query paging logic is not executing in the database

How can I make my Linq to SQL query logic execute on the server? I have a created a Linq query and returned it as an IEnumerable. Subsequent operations on the query such as .Count() or .Take(5) are evaluated on the client in CLR, rather than on the server. ...

LINQ to SQL update problems in WPF application

Hi everybody! I'm developing a WPF application (.NET 3.5SP1). The scenario is this: 1.using SQL Metal to extract the entity definitions (and the corresponding map file), which were afterwards used for the Data Access Layer (so i'm using LINQ to SQL). 2.using Unity (this application is "PRISM based") to register abstract classes and the...

Return Multiple Columns in Linq to Sql?

Hi How do I return multiple columns with linq to sql in C#? I tried to end my query with select new { A.Product, A.Qty }; but this returns some anonymous type and I am not sure what the heck what to do with this, How to return it and how to extract information out of it. I want to put it in some sort of array. thanks ...

Why won't entity framework allow me to do a .FindBy....()

I create a EDM using my database and saw that while it was able to make relations like Customers.First().Orders there is nothing like Customer.First().Orders.FindOrderByOrderID() Customer.First().Orders.FindOrderByOrderName() etc. Maybe I was expecting it to be like that and that's how it doesnt work and I will probably just have...

3 Nested Repeater Using LINQtoSQL To Implementing N-N Relation

I have 3 tables in my DB. I implemented a N-N relation using "AccountAccessRight" Table as a junction Table. So "Account" Table has 1-N relation with "AccountAccessRight" and "AccountAccessRight" has N-1 Relation to "NextOfKin" Table. Iwant to list every Account and List every NextOfKins of each account In "Repeater1". Here is DB Diagra...

LINQ Distinct and IEquality

How would I specify the id field of an object in a list of objects as the disctinction? Selections.Distinct(); ...

Linq & unsupported data types (Geography)

So, Linq does not support the Geography data type, which throws a major spanner in the works in the lovely 'drag table onto the Linq design surface' developemnt model. Is there any way that I can extend Linq to work with the Geography datatype? Or will I need to build a whole new datalayer and set of queries for whenever I need to use G...

Efficiently selecting a tree in Linq-To-Sql

Hello! I have a linq-to-sql data layer, with 2 tables in it. "Parent" and "Child". There's a relationship between Child and Parent (so parent has many children, etc etc), a parent can also have many parents (when children grow up and themselves become parents). I want to display this hierarchy out to the user, but I'm not sure how to...

Utility to Create DBML

Is anyone aware of a free utility, preferably with source code, that will create a Linq-to-SQL DBML based on the contexts of a SQL Server database? I realize Visual Studio can create one, but I don't want to have to drag hundreds of tables onto the L2S canvas just to create a DBML. Thanks very much - Randy ...

I can't see the extension methods of LINQ to SQL in Class Library

Hi Everyone, I created a Class Library named Repository and which includes LINQ To SQL file which stores a ORM of SQL Server Database, besides that I also created another Class Library named Services which has the reference of the Repository class library and I want to use the LINQ to SQL file locating in Repository in Services but I ca...

How to generate entities to database

I create a linq to sql class Create all entities that i need for my app Now i need to create this entities in the database is there a way to generate all of my entities? yes i want to generate tables for the entities ...