linq-to-sql

How do I design backing data types for a databound WPF dialog with Ok/Cancel buttons?

I've created a table in Microsoft Sql CE that I'm using to hold some data. I've generated an ORM via SqlMetal and I've pulled the datasource into my WPF project. I want to create a simple WPF form that can be used to edit a record in the table via the ORM-generated classes. I want this form to support typical OK/Cancel semantics. I'v...

Migration From Datatable to Linq to Sql

In past I use dynamic sql and datatable to get data from database. Such as : Public shared function GetUsersByUsername(byval username as string) as datatable dim strSQL as string="select * from Users where Username= " & username return dbClass.datatable(strSQL) end function And I could use this data such this: Dim Email as str...

Thoughts on Entity Framework

I was wondering what people thought about the decision to support Entity Framework over LINQ-to-SQL? I have an application I'm developing originally in LINQ-to-SQL. I found it the perfect solution for our application. While attempting to port to Entity Framework I was surprised how rough it was. IMHO, not even close to being ready f...

Best way to do multiple table associations in a LINQ dbml file?

I have a couple of tables in my database, one called Task, and another called User. The Task table has two columns CreatedBy and ModifiedBy that map to the UserId column in the User table. I want to add the User table to the dbml file and add the associations. I notice now that when I look at class I have two properties one called Use...

Linq: multiple relationships to same table

I have the same problem as this guy: I have a table that has references my tblstaff table twice for two different people. Now that I have added this second reference neither of them work. What is up w/ that? ...

How do you do an IN or CONTAINS in LINQ using LAMBDA expressions?

I have the following Transact-Sql that I am trying to convert to LINQ ... and struggling. SELECT * FROM Project WHERE Project.ProjectId IN (SELECT ProjectId FROM ProjectMember Where MemberId = 'a45bd16d-9be0-421b-b5bf-143d334c8155') Any help would be greatly appreciated ... I would like to do it with Lambda expressions, if possible....

LINQ across multiple databases

I've got two tables that need to be joined via LINQ, but they live in different databases. Right now I'm returning the results of one table, then looping through and retrieving the results of the other, which as you can guess isn't terribly efficient. Is there any way to get them into a single LINQ statement? Is there any other way to co...

How do I use sqlmetal to generate an internal (not public) data context

I'd like to use sqlmetal to generate dbml data contexts for my project, but the data context and all classes created are marked as public. As this is supposed to be an API layer I'd like to instead mark many of these classes or at least the context itself as internal. Is there a way to do this in sqlmetal or some other tool without havin...

Is linq2sql behind the scence equal to Entity Framework

i know its a new thing , more powerful and a lot more options added to it, but is linq2sql is part of the new EF ? if not , what is the main different between the two frameworks? ...

LINQ-to-SQL CompiledQuery.Compile() with Update, Delete, Insert?

All, So I've got all my select queries in LINQ-to-SQL converted to using CompiledQueries to speed things up. Works great so far for select statements, but I haven't been able to figure out how to pre-compile insert, update, or delete statements. Granted, when you're inserting, deleting or updating in LINQ-to-SQL, you have to use the o...

How do you create optional associations in Linq-To-Sql classes?

I am trying to creating an optional association between a couple of tables. I have one table called Invoice. The Invoice table has a FK reference to the Customer table through the CustomerId field. The Invoice table also has a not enforced FK reference to the Project able through the ProjectId field. Is there anyway to set up my Linq...

What strategy should I take now that MS will no longer support LINQ to SQL?

Please if you have used NHibernate and Entity Frameworks, please contrast your experiences. ...

LINQ to SQL object versioning

I'm trying to create a LINQ to SQL class that represents the "latest" version of itself. Right now, the table that this entity represents has a single auto-incrementing ID, and I was thinking that I would add a version number to the primary key. I've never done anything like this, so I'm not sure how to proceed. I would like to be able ...

Encapsulating LINQ select statement.

I have LINQ statement that looks like this: return ( from c in customers select new ClientEntity() { Name = c.Name, ... }); I'd like to be able to abstract out the select into its own method so that I can have different "mapping" option. What does my method need to return? In essence, I'd like my LINQ query to look like this: return...

Hanging Linq query with Guid.Empty in the where expression

I'm having an issue with the following code: private void DataPortal_Fetch(TaskCriteria criteria) { using (var ctx = ContextManager<Gimli.Data.GimliDataContext> .GetManager(Database.ApplicationConnection, false)) { this.RaiseListChangedEvents = false; this.IsReadOnly = ...

When are records from related tables loaded with LINQ2SQL

Let's say I have two tables: Report Comment And assuming I have a database context: var reports = db.Reports(); How can I make sure all Comments for each report are loaded as well? At this point I want to disconnect from the database but still have access to the comments. (For example:) reports[0].Comments[0].Subject ...

How to tell if SubmitChanges() will actually change anything for a particular entity in LINQ to SQL

I'm trying to determine if any changes were made to a particular entity object. Essentially, I want to know if SubmitChanges() will actually change anything. I would prefer to be able to determine this after SubmitChanges() has been called, but it doesn't really matter. Anyone know how I would do this? ...

What's the best way to handle "type" tables with LINQ to SQL?

I have some tables that represent various types. They usually just consist of an ID (int), and a name. Ideally I would have this in an enum. Is there a way to map a table like this onto an enum? EDIT: How would I handle it if there were extra fields other than an ID and Name? ...

Updating value in Linq to SQL IEnumerable

Using Linq to SQL: if(!parentlist.childlist.Contains(row1)) parentlist.childlist.Add(row1); else How do I update the required childlist row with row1? Each row of the child list has a unique id. parentlist implements IEnumerable and childlist is IList. ...

Linq to SQL File Size

Hi, What I wanna learn is if we put every table into one LinqToSQL file, do we lose performance ? Is it better to put each table in different LinqToSQL Files or it's the same thing with putting in single one. I hope I could explain my question. Thanks and Regards... ...