linq-to-sql

wcf serialize linq results causes massive sql server load

Hello, I am trying to get serialized results from a WCF service from database using linq. The tables in the db are normalized to some extent and I'm returning some other data along with the on that I initially retrieve with a linq query using Data.Linq.DataLoadOptions, just like in Scott Landford's Blog: http://codeexperiment.com/post...

[Silverlight] WCF RIA Services Issue With Updating

I am running into an issue with refreshing data on a page after doing an update through WCF RIA Services. I have a ComboBox and a Button on a page. The user chooses an item from the ComboBox, and then clicks the Button. This does a soft delete of the item in the database(setting "Active" = false). However, I would like for it to be remo...

Translate LINQ Inline query to extension method

I can't seem to figure out the LINQ Join extension method... I have the following LINQ inline query: var cc = from z in zipcodes join c in contactsRepo.UDF_SelectSome() on z.Zipcode equals c.Zip What is the equivalent of this in LINQ-extension-method syntax? ...

How to get the max row number from a table by using linq

SELECT ISNULL(MAX(ColumnName) + 1, 1) AS ColumnName FROM TableName How to write this query in LINQ.Is there any way to convert sql to linq . i want a converter. Above query works well but i want the same output on linq .How to ? I know how to select max var products = ((from p in db.TableName select p...

LINQ 2 SQL Return Multiple as Single String

I have a 1 to Many relationship between tblBusiness and tblPhone. For a specific BusinessID I am trying to return a single string of information to bind to a textbox. Below is my latest attempt along with the Generated SQL from that same LINQ. No matter WHAT I have tried it returns NULL unless there is a value for all 3 fields. What ...

LINQ And Concurrency Question

I am developing three applications that all share a common database. I'm running into many different concurrency issues and was wondering if it is possible to prevent any other queries to execute when certain queries are running (in other words, locking the database so there won't be any concurrency issues). Edit: I'm using LINQ to SQ...

How to do a join in linq to sql with method syntax?

Hi I seen lots of examples in linq to sql examples on how to do a join in query syntax but I am wondering how to do it with method synatx? like I am confused on how to use .join(). Can anyone give a simple example? ...

LINQ to SQL find average of field?

I have a ViewModel called EntityRating, one of whose properties is AverageRating. When I instantiate a new object of my ViewModel (called EntityRating) type, how do I set the EntityRating.AverageRating based on the Rating field (in SQL Server) of the item in question? I want to do something like this (which obviously doesn't work): va...

LINQ2SQL : Auto-Sync=OnInsert

I have a column named CreationDate for which I set Auto Generated Value = true Auto-Sync=OnInsert It is working perfectly well however I still wondering why it is synchronized when I do an UPDATE Here what SQL Server profiler shows when I update any column in this table exec sp_executesql N'UPDATE [dbo].[T_Address] SET [CountryCo...

Use Replace Method In Linq-Sql Query

I used RegEx to remove HTML TAGS within LINQ-SQL query but the following error has thrown: Method 'System.String Replace(System.String, System.String, System.String)' is not supported for execution as SQL. Help helpDBSession = new Help(); IEnumerable<Article> articles = null; if (lang.ToLower() == "en") ...

In linq how dynamically pass table and column name

I want to write an dynamic linq where i send table and column name this query return me the max row number of the table . SELECT ISNULL(MAX(intProductCode) + 1, 1) AS intProductCode FROM tblProductInfo Above is my T-SQL syntax.I want same output from the linq how to If i write this bellow syntax get same out put but here i can not se...

L2S, Caching, and error: The query results cannot be enumerated more than once

I have a fairly complex query (that includes a table valued function to allow full text searching) that I am trying to cache (HttpRuntime.Cache) for paging purposes. When I try to use the cached L2S query, I get the error stated above: The query results cannot be enumerated more than once. I have tried assigning my query to another IQue...

Send Two Models into One View .Net in VB

Edit one more time: So it looks like I have figured out the address part too, in the class I have: Public ReadOnly Property addresses As IEnumerable(Of Address) Get Return _these_addresses End Get End Property And in the template I have: <% For Each item In Model.addresses%> <tr> ...

how to add default element in sequence if is empty? using DefaultIfEmpty()

i have query that maybe haven't any element on sequence and i want to add one element to sequence if is empty. var results = _context.Documents.Select(document => document.MimeType).Distinct().ToList().DefaultIfEmpty("There is nothing to be used as MimeType"); but still sequence is empty however is used DefaultIfEmpty method. ...

How to save a SQL Server image data type to the file system?

I'm having issues with the way I've been reading my image datatype blobs from my SQL database (code below). This code works fine when I access this page directly. The PDF will open and works just fine. However, when I try to use this page to download a file and save it to the file-system programmatically, it fails (500 server error) a...

DAL + BLL + LINQ + Enterprise Library 5 + .net 3.5

What are the Best practices for coding Data Access Layer and Business Logic Layer with combination of LINQ and Enterprise Library 5.0 in .net 3.5? ...

what type does my object query return?

Public Function List_category() As Myobj Dim query = From subcat In _dataContext.subcategories, _ cat In _dataContext.categories _ Where subcat.CategoryID = cat.CategoryID _ Select New Myobj() With { _ .SubcatId = subcat.SubCategoryID, _ .SubcatName = subcat.SubCategoryName, _ ...

Trap Foreign Key constraint error with Linq2Sql

I have a gridview bound to a linq data source. When I try and delete a row from the grid I get a FK reference contraint violation. I'm not sure where/how to trap the foreign key exception. I tried the GridView1_RowDeleting and the LinqDataSource1_Deleting event but I can't seem to trap it at that level. ...

Looking for an open source project based on Linq to SQL

Hei I’m trying to learn Linq to SQL and wondering if somebody can suggest some demo/open source project based on Linq to SQL. Preferably full designed n–layer architecture, showing best practices. Thanks ...

ASP.NET MVC LINQ-2-SQL as model - how to update?

Is it possible to use LINQ2SQL as MVC model and bind? - Since L2S "attachement" problems are really showstopping. [HttpPost] public ActionResult Save(ItemCart edCart) { using (DataContext DB = new DataContext()) { DB.Carts.Attach(edCart); DB.Carts.Context.Refresh(RefreshMode.KeepChanges, edCart); DB.Carts.Context.S...