linq-to-sql

LinqToSql - Include linked object in selected result

I have two tables. Linked with a foreign key. Now I fetch a row from the field table: IField Field = from f in DataContext.fields where f.mapId == mapId && f.x1 == x && f.y1 == y select f; Working with this row I need some data from the linked table fieldViews. So I just do somthing like this: [..] Fi...

Linqdatasource group by problem with multiple table

I'm using linqdatasource for displaying data in listview (nested because of grouping) control. I want to display data from more than one table. I'm using VWDExpress. ...

if I got a List(of t) how to filter out item from a linq 2 sql query?

I have a list(of t) and I got a iqueryable(of a) I want to filter out any item from the iqueryable(of a) where a.id = t.myotherid I'm not really sure how to write this query, anyone could help me here? For now I got this Dim listCie = (From c In db.getListCompany() _ Where Not rels.Select(Function(a) a.ChildID).Contai...

Linq-to-SQL datacontext not generating an object

I am working in a .NET 2.0, recently upgraded to .NET 3.5 environment (VS2008, VB.NET) on an existing ASP.NET website project. I am able to generate a Linq-to-SQL Class (also called a DataContext?) in the App Code folder, drag over tables from an active connection, and save it. Let's call it MyDB. When I go to the code-behind file for my...

how to design Repository pattern to be easy switch to another ORM later?

I am new to repository pattern but i tried, my goal is to make a design which will let me easily with just some few edits "dependency injection, or configuration edits" to be able to switch to another ORM without touching other solution layers. I reached this implementation: and here is the code: public interface IRepository<T> { T ...

Linq to SQL & Castle IoC Container sanity check please

I've just started using both Linq to SQL and Windsor Castle IoC container for a new web app and, although things seem to be working OK in preliminary tests, I could really do with a sanity check on it. I was running into problems when I tried to pull objects out of the database using Linq in different parts of the app and then updating ...

Is there a library with an alternative InsertAllOnSubmit implementation which uses SqlBulkCopy?

We know that Linq-To-Sql InsertAllOnSubmit sucks in terms of performance, but using SqlBulkCopy for mass insertions requires some coding. Have anyone found any code/library that uses SqlBulkCopy in a InsertAllOnSubmit alternative implementation as simple to use as the original? ...

Linq function based on stored procedure which does count(*) returns null

I have a SQL Server 2008 stored procedure which does a select count(*) ... I have a LINQ function called GetCount() based on that SP. When I do something like: int? count = datacontext.GetCount().Single().Column1; count is null. The SP never returns null. Why is count null? ...

LINQ to SQL Update (C#)

Hello all, This is the script of my table: CREATE TABLE ClientTypes ( type_id int PRIMARY KEY IDENTITY, type_name varchar(250) not null, type_applications_list text, dtIntro datetime DEFAULT(getdate()) ) And in ASP.net i'm trying to do this: protected void btnActualizar_Click(object sender, EventArgs e) { ...

LinqtoSql - FirstOrDefault - How do I test for default returned

I am using the FirstOrDefault<T>() method to return an object from a Linq2Sql query. I then set an object to be equal to the returned value. how do I test if the default has been returned? ...

confused about linq and IEnumerable or IList

Can someone explain why i get an 'no translations to sql' error in 'results' statement if GetAddresses() returns IList but not if it returns IEnumerable? var addresses= GetAddresses(dataContext); results = results.Where(r => r.People.Any(a => Addresses.Contains(a))); ...

Is Linq to SQL still a viable choice for developing applications?

I'm reading up on .NET things again after a brief (and occasionally ongoing) stint with Ruby on Rails. I'm wondering if LINQ is still a choice when choosing an ORM for new applications, or if I should learn something like NHibernate instead which seems to still be going strong. I know that Linq has basically been subsumed by the Entity...

Is it a bad idea to jump into LINQ to SQL now?

I have been using ADO.NET in favor of LINQ to SQL (or Entities) up to this point. I'm starting a new project that should be smallish, at least at first but I would like to have room to expand down the line. I feel now is a good time to get into LINQ. I've avoided it for quite a while; however, I'm concerned by the current direction of...

Set value array with a query

I want to set this Array with the result of ths Query but I can't. How do I do it ? String[] q = (from p in MDB.aspnet_Memberships where p.aspnet_User.aspnet_UsersInRoles.Single().aspnet_Role.RoleName.ToString() == GroupDDL.SelectedItem.ToString() select new{p.UserId }).ToArray(); Exception ...

Linq update with explicit operator

Hi, I am trying to do an update with linq using an explict cast and the changes arent submitting. Here is the code Image update = db.Images.Where(i => i.ImageId == imageWithChanges.ImageId).SingleOrDefault(); update = (Image)imageWithChanges; db.SubmitChanges(); I have an explicit operator in my image class. Can anyone help? Tha...

3rd party LINQ to SQL / EF designer search features add-on

I am searching for this feature: To search for an entity, relation ... etc in the designer. In EF designer the model browser window make finding entities a little easier but in LINQ to SQL there is no such thing. Also searching in the designer area is not available at all. I am wondering if I am the only one who sees this a s requirement...

System.InvalidCastException: Specified cast is not valid when inserting a record in LINQ to SQL

On my development machine everything is working fine, however as soon as I publish it to the server I get System.InvalidCastException: Specified cast is not valid This is happening on db.SubmitChanges(); I've check out https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=351358 and it still causes me e...

Linq to Sql: How to clear a table fast

To delete all the rows in a table, I am currently doing the following: context.Entities.DeleteAllOnSubmit(context.Entities); context.SubmitChanges(); However, this seems to be taking ages. Is there a faster way? ...

Any libraries available for doing LINQ over EAV pattern?

Does anyone know of any libraries which implement an abstraction in LINQ over the EAV (Entity Attribute Value) pattern? I have a large legacy EAV database and I'm trying to create a cleaner data access layer and the thought of using LINQ really appeals so I'm looking for any code I can use to jumpstart. ...

In C# can you create a new inherited object by assigning it a copy of its base object?

So if class C inherited from class B and has one extra property, could I create a new object of class C by passing it an object that already exists of class B and it will either leave the extra property null or run some LINQ to SQL to see what the extra property should be (such as for a counter, etc)? C c = new C(); B b = bRepo.getBbyID...