linq-to-sql

I'm sure someone has seen this: Cannot remove an entity that has not been attached. with LINQ

…衆ロ難τιáo~ 提交于 2020-03-25 03:35:40
问题 The scenario I am using LINQ is as follows: I have a method that queries a table and returns one record using the following code private L2SQLData.PatientFile getpatfile(long id) { var db = new HMSDataContext(); var patfile = (from f in db.PatientFiles.Where(f=> f.Id == id) select f).FirstOrDefault() ; return patfile; } Then another code calls the method above and takes object/record that was returned. Then deletes it from the same table as follows: L2SQLData.PatientFile patfile = getpatfile

How to make Exists with Dynamic Linq

﹥>﹥吖頭↗ 提交于 2020-02-25 03:18:27
问题 How to do I make exists with dynamic LINQ? I'm trying to create an SQL clause with dynamic LINQ. I researched a lot of and not found an satisfactory answer. I try convert the SQL query as follows: SQL select * from Documento where exists( select 1 from Titulo where Documento.codDocumento = Titulo.codDocumento and Documento.codEmpresa = Titulo.codEmpresaDocumento and Titulo.codFluxoConta = 'SomeValue' and Titulo.codEmpresaFluxoConta = 'StringNumerical') In common LINQ I did as follows: var

Multiple textbox insert into to sql table in separate rows using LINQ

亡梦爱人 提交于 2020-02-23 04:32:08
问题 Inserting values of text boxes into specific columns of a single row of a sql table usign LINQ is not a big deal but how to insert content of each textbox in new row, for example if we have 5 text boxes so it should create 5 new rows in sql table. Below is how I insert text boxes into different columns of a single row : Table Name: tblModulRelayConfig index fltCe fltUT1 fltUT2 fltUT3 fltUT4 fltUT5 fltUT6 1 75 Text1 Text2 Text3 Text4 Text5 Text6 2 76 Text1 Text2 Text3 Text4 Text5 Text6 using

Can't Add LINQ to SQL classes to projects in VS2010

大憨熊 提交于 2020-02-21 13:16:25
问题 I just ran into something in Visual Studio 2010 RC that wasn't previously happening (like, yesterday). No software changes here, but I did run into some muck yesterday when compiling that required a reboot. I am unable to add LINQ to SQL classes to any project through the add dialog. I have created ASP.NET web sites, ASP.NET MVC projects - both of these as 'templated' and as 'empty' - and there appear to be no templates installed or available. alt text http://bandofgeeks.net/blogimages/code

Stop LINQ to SQL from executing select statements after insert

这一生的挚爱 提交于 2020-02-20 00:59:22
问题 I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database. Do you know I can prevent LINQ to SQL from issuing the select statements after the insert statements? This should make my app much faster. 回答1: You're looking for ColumnAttribute.AutoSync. If you're using the designer, check each

Stop LINQ to SQL from executing select statements after insert

巧了我就是萌 提交于 2020-02-20 00:57:09
问题 I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database. Do you know I can prevent LINQ to SQL from issuing the select statements after the insert statements? This should make my app much faster. 回答1: You're looking for ColumnAttribute.AutoSync. If you're using the designer, check each

Stop LINQ to SQL from executing select statements after insert

为君一笑 提交于 2020-02-20 00:56:03
问题 I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database. Do you know I can prevent LINQ to SQL from issuing the select statements after the insert statements? This should make my app much faster. 回答1: You're looking for ColumnAttribute.AutoSync. If you're using the designer, check each

How to use union all in LINQ?

落爺英雄遲暮 提交于 2020-02-17 06:54:25
问题 How to use union all in LINQ TO SQL. I have use the following code for union, then how to use this for union all? List<tbEmployee> lstTbEmployee = obj.tbEmployees.ToList(); List<tbEmployee2> lstTbEmployee2 = (from a in lstTbEmployee select new tbEmployee2 { eid = a.eid, ename = a.ename, age = a.age, dept = a.dept, doj = a.doj, dor = a.dor }).Union(obj.tbEmployee2s).ToList(); 回答1: Concat is the LINQ equivalent of UNION ALL in SQL. I've set up a simple example in LINQPad to demonstrate how to

How to group certain element then after add item of specific criteria doing linq to sql in c#

风流意气都作罢 提交于 2020-02-16 10:39:07
问题 This might seem like a stupid question but i really need help. I don't often post question but this time i really help. I need to have a linq to sql query that groups multiple columns. But not just that, one of the columns have specific that also need to be grouped base on certain condition . The Query i have is this one. using (var donnée = new ClassDonnéeDataContext(mycontrng)) { var don = from d in donnée.Reservations where (d.Date_Livraison.Value.Date == startDate.Value.Date) && d.Sortie

Conditional Linq Queries

纵然是瞬间 提交于 2020-02-08 19:26:34
问题 We're working on a Log Viewer. The use will have the option to filter by user, severity, etc. In the Sql days I'd add to the query string, but I want to do it with Linq. How can I conditionally add where-clauses? 回答1: if you want to only filter if certain criteria is passed, do something like this var logs = from log in context.Logs select log; if (filterBySeverity) logs = logs.Where(p => p.Severity == severity); if (filterByUser) logs = logs.Where(p => p.User == user); Doing so this way will