linq-to-sql

Repository, Entity objects and Domain Objects

In my Repositories, I am making assignments to my domain objects from the Linq Entity queries. I then have a service layer to act on these object returned from repositories. Should my Domain objects be in the repository like this? Or should my repositories be restricted to the Entities and Data Access, and instead have my service layer...

DataContext Refresh and PropertyChanging & PropertyChanged Events

I'm in a situation where I am being informed from an outside source that a particular entity has been altered outside my current datacontext. I'm able to find the entity and call refresh like so MyDataContext.Refresh(RefreshMode.OverwriteCurrentValues, myEntity); and the properties which have been altered on the entity are updated corr...

ADO.NET Data Services with Linq-to-SQL

I am encountering a weird error when using linq-to-sql with ado.net data services. I have a simple silverlight application that connects to a remote database. I first added the linq-to-sql class and dragged a table onto the designer. Then I added a ADO.NET Data Service, updated the DataService reference to point to the L2S Data context. ...

Linq to SQL or Linq to DataSet?

I am new to Linq world and currently exploring it. I am thinking about using it in my next project that involves database interaction. From whatever I have read, I think there are 2 different ways to interact with databases: Linq to SQL Linq to DataSet Now the product that I am to work on, cannot rely on the type of database. For ex...

Linq To SQL Without Explicit Foreign Key Relationships

I am working with a few legacy tables that have relationships, but those relationships haven't been explicitly set as primary/foreign keys. I created a .dbml file using "Linq To Sql Classes" and established the proper Case.CaseID = CaseInfo.CaseID association. My resulting class is CasesDataContext. My Tables (One to many): Case ---...

Return related objects in select linq to sql

I have 2 tables Account and Address which has 1:1 relationsip; account has addressid in it. I have created the association in the dbml file. Now I want to write a query to select the account for given accountid and the resulting account should contain the address object in it as well. using (var context = new SalesLogixDataClassesData...

C# LINQ problem with case sensitive

Hi! I have this: var sortName = Request.Params["sortName"]; var query = Request.Params["query"]; Func<UsuarioEndereco, bool> whereClause = (uen => uen.GetPropValue<string>(sortName).Contains(query)); The "uen.GetPropValue<string>(sortName)" will be filled dynamically with the sortName the user typed in the page. For example, if an...

.NET and database layers

When I last worked in programming, we were trying to move away from DataReaders and the traditional ADO.NET API toward Object Relational Mapping (ORM). To do this, we generated a DataContext of our DB via sqlmetal. There was then a thin data layer that made the DataContext private, and any code needing to access the database would have ...

How to fix this linq to sql query that has no support translation to sql?

Hi folks. i've got a LinqToSql query with a custom extension method at the end. this extension method is erroring when I try to linq2sql tries to generate the sql statement. Error: Method 'System.Collections.Generic.IList1[System.String] ToListIfNotNullOrEmpty[String](System.Collections.Generic.IEnumerable1[System.String])' h...

Method 'Boolean Contains(System.String)' has no supported translation to SQL.

"Method 'Boolean Contains(System.String)' has no supported translation to SQL." query is IsQueryable but this stopped working: foreach (string s in collection1) { if (s.Length > 0) { query = query.Where(m => m.collection2.Contains(s)); } } UPDATE: it works when i make query ...

Linq2Sql: Does HasValue and != null, work the same for nullable types?

Is there any reason why I should choose one of these over the other? Or doesn't it really matter? var a = data.Cars.Where(ø => ø.LicensePlate != null); var b = data.Cars.Where(ø => ø.LicensePlate.HasValue); I have used != null before, but starting to think I should maybe switch, since HasValue kind of reads better. What do you guys t...

Is Linq-To-SQL getting scrapped?

Duplicate: Is LINQ to SQL DOA? I read somewhere on the 'net that Microsoft is considering moving away from LINQ-To-SQL in its current form as it wasn't very successful. I want as many opinions on this as possible as I'm new to .NET and want to choose the best possible route for where I work. ...

High volumn site using ADO.NET TransactionScope vs ExecuteCommand on NOLOCK, READ UNCOMMITTED directly?

Just read this interesting article by Omar on his blog Linq to SQL solve Transaction deadlock and Query timeout problem using uncommitted reads and at the end Javed Hasan started arguing with him about his solution to the nolock situation on a high volume site. Here, the problem trying to solve is, from the sql sense we need to use Se...

Why does calling full text search in SQL Server 2008 fail when inside transaction scope?

The following code: var foo = Users.Join( tvf_SearchUsers(queryString), u => u.User_Id, s => s.User_Id, (u, s) => u); Selects users that match the query string based on a table valued function (tvf_SearchUsers), which utilises full text search. This code snippet is part o...

Can I use the Entity Framework like I use LINQ to SQL?

I've begun experimenting with LINQ to SQL and what I am doing is basically creating classes with LINQ mapping decorators - thereby choosing which parts of the db table schema I want to incorporate into my classes. A simple example: private DateTime? _LocalCopyTimestamp = (DateTime)SqlDateTime.MinValue; [Column(Name = "recaLocalCopyTime...

Difference between Expression.Call overloads?

Hi, I was attempting to dynamically create a Where predicate for a LINQ2SQL query: ...Where(SqlMethods.Like(r.Name, "%A%") || SqlMethods.Like(r.Name, "%B%") || SqlMethods.Like(r.Name, "%C%") || ...) A, B, C, etc. come from some array. So I tried the following: var roleExpression = Expression.Parameter(typeof(Role),...

Weird linq2sql/let bugs?

Can someone explaing why existence of the following linq query... (from e in db.Clients let log = (from f in db.CreditsafeLogs where f.Vat.Equals(e.VAT) orderby f.Sent descending select f).FirstOrDefault() where e.DeleteFlag.Equals("n") && e.Active == true && log != null && lo...

Why does ToDictionary<K,V>() generate a compiler error when used with LINQ to SQL?

Hi All, Following on from this question: Linq-to-SQL ToDictionary() I have a table called Domains, it has two columns: DomainID int DomainName varchar(250) I want to return a Dictionary<int, string>. When I try either of the following LINQ to SQL code: Dictionary<int, string> dict = dbc .Domains .Select(d => new {d.Dom...

How to add several dependent records with LINQ2SQL

Hi. I have two tables. One table contains comments on posts, another contains commenter information like nickname, site, etc.. There is FK relations betwin two tables Comment.CommenterId -> Commenter.Id Whenever user posts a comment I need to add comment and commenter at the same time. The problem is that I don't know what would be Comme...

Linq to sql: properties of properties that may be null

Simple LINQ query: from transport in db.Transports select new { Current = transport.CurrentLocation, CurrentCarriers = transport.CurrentLocation.Carriers, }; Problem: CurrentLocation may be null. If it is, executing this query throws a NullReference. I tried adding a check like transport.CurrentLocation == null ? null : ...