linq-to-sql

mimicking triggers in LINQ

Hi everyone, I have a question about implementing triggers at hi level, c# .net code; Is that possible at all? I have to develop a browser on exiting database. I need to have some triggers on some of tables and I cannot,allowed, do this with sql trigger commands? I am using linq for achieveing other functionalities and making connection...

Linq query aggregate by month active

I have a seemingly simple requirement, but i can't figure out how to write it as a query that only has one round trip to the server. Basically i have a simple table CREATE TABLE Item ( id int not null identity(1,1), create datetime not null, close datetime --null means not closed yet ); and what i want to do is over a ran...

Ranking. Linq to sql question

I have a table of orders made by persons: Orders { Guid PersonId, int Priority, Guid GoodId } Priority is some integer number. For example: AlenId 1 CarId DianaId 0 HouseId AlenId 3 FoodId DianaId 2 FlowerId I want to retrieve highest priority orders for each person: AlenId 1 CarId DianaId 0 HouseId ...

Linq-to-SQL with a table valued UDF user defined function

I am new to Linq and trying to get a handle on how to bind a drop down to a SQL user defined function. //Populate the Pledge dropdown var db = new App_Data.MyDBDataContext(); int? partnerID = Convert.ToInt32(Request.QueryString["PartnerID"]); var pledges = from p in db.ufn_AvailablePledge...

Error connecting to SQL from WCF Using LINQ - but affects only one server

That's a horrible title, sorry. Here's the scenario: WCF Service uses LINQ to get data from a SQL database. Service is deployed on 4 (nearly) identical servers running under IIS. All are talking to the same SQL server on a separate machine. 3 of the 4 servers are working great. On the 4th server we're getting this A network-rel...

How to learn transaction in EF or LINQ to SQL?

i try to learn transaction scope. Everything looks good. i try to control transaction is running i add 500 char in NAME value (Name nvarchar(50) normally). While My formApplication not running (it is normal), i try to open a table table is empty. Stop running my app form . i can see values of Tables. WHY? using (var ctx = new DataClass...

How can i do insert more data with insert query with more select statment linqToSQL?

How can i use insert into myTABLE (. . . .. . ) select * from(.......). I try to write some linq query but i can not. Look please linq query. SQL: INSERT INTO ActualAmountsByLocation (ItemBarcode, Location, LocationName, Amount, isCustomerItem, LastUpdate) SELECT * FROM (SELECT DISTINCT m.ItemBarcode, ...

How can i use in ( select method in linq?

how can i write "in( select" method in linq? I'm trying to convert : UPDATE ActualAmountsByLocation SET isCustomerItem=1 WHERE ItemBarcode IN (SELECT barcode FROM StockMaterials WHERE barcode=@Barcode AND ownership=1) I've tried like this: Array stockMaterials = ( from s in stockMovementCtx.StockMaterials where s.barcode == Barc...

Linq2SQL "Local sequence cannot be used in LINQ to SQL" error

I have a piece of code which combines an in-memory list with some data held in a database. This works just fine in my unit tests (using a mocked Linq2SqlRepository which uses List). public IRepository<OrderItem> orderItems { get; set; } private List<OrderHeld> _releasedOrders = null; private List<OrderHeld> releasedOrders ...

LINQ-to-SQL retrieving data from a different query!

I have a web application that uses LINQ-to-SQL. It has a very strange issue, where a LINQ command retrieves the data that is supposed to be returned by another, totally different query that runs in a different thread. What could be the cause of this? Specifically, a user accesses the application from his machine, opening a certain page....

How can I get distinct records from many to many relationship using Linq to Sql

For brevity, let's say I have the following 3 tables (m:n): Articles, Topics and a joining table ArticleTopic. I need to get the top n articles for n topics. Each article should only show once for the entire result set. Article: -Id -Title Topic: -Id -Name ArticleTopic: -Id -ArticleId -TopicId Thanks for your help! ...

Alternative to using string.Join in a LINQ query?

Any time I use the code below it throws the error: Method 'System.String Join(System.String, System.Collections.Generic.IEnumerable`1[System.String])' has no supported translation to SQL. var items = from t in fc.table where t.id== objId select new { ...

Database updating incorrect values when passing object from Controller to Repository.

I've got a Controller ActionResult that looks like this Function Edit(ByVal user As Domain.User, ByVal id As Integer) As ActionResult Dim _user As Domain.User = user If ModelState.IsValid Then If Not String.IsNullOrEmpty(user.UserName) AndAlso _ Not String.IsNullOrEmpty(user.WebSite) AndAlso _ No...

How to use the NOEXPAND hint with Linq to SQL?

I have an indexed view that I need to specify the noexpand hint for in order for it to perform reasonably. Unfortunately as seen with regard to modifying the Linq to SQL generated T-SQL query from the NOLOCK hint it appears that there is no easy way to take advantage of these hints directly or is there? My thought is that it would make ...

How can I solve "The query results cannot be enumerated more than once"?

if i try to write below codes : error return to me: The query results cannot be enumerated more than once public void StartTransaction() { using (var stockMovementCtx = new StockMovementCtxDataContext()) using (var scope = new TransactionScope()) { var stockMovementItems = f...

How to set all column atrribute"UpdateCheck" quicly for all tables?

Hi, i need to set LINQ UpdateCheck attribute of columsn in every tables in mine db, is there any quick way to set all column's updatecheck attribute? ...

LINQ DataContext inserts object that is not attached

I have created two separate objects, one of class Order and one of class TempOrder. When I try to insert the TempOrder object in the db using db.TempOrders.InsertOnSubmit(obj) and then calling db.SubmitChanges the Order object gets submitted as well (without being attached to the datacontext or anything). There is no relationship betwe...

LINQ to SQL Basic question - table relationships

I'm playing with an image gallery in ASP.NET MVC, and trying to get my head around LINQ to SQL at the same time. I have 3 tables to hold image gallery data, with a many-many relationship through a link table. These are : Gallery (Id, Name, Description) Image (Id, Title, Description, FileName) GalleryImage (Galle...

How can i enable Transaction my codes with linqto SQL?

if writing below codes: Error returns.i do like advise : http://stackoverflow.com/questions/794364/how-do-i-use-transactionscope-in-c But only error change:The partner transaction manager has disabled its support for remote/network transactions Exception from HRESULT: 0x8004D025 i am using windows server 2003. using (var stockMov...

LINQ VB.net Return Single Type of Object Invalid Cast

Ok, just needing a 2nd set of eyes looking at this to make sure the error isn't something else other than my LINQ code here.  Here's the function class itself: Public Function GetJacketByPolicyID(ByVal jacketID As Int32) As tblPolicy Dim db As New DEVDataContext() Dim j As tblPolicy = db.tblPolicies.Single(Function(p) p.policyNumb...