|
|
August 2008 - Posts
-
Hi ! I have a web page with GridView in it, which gets its data from my DataAccess layer using LINQ-to-Sql. My problem is with getting the latest database state ... In ADO.Net it was easy to cache my table and then use SqlDependency to poll the database for changes. In LINQ I figured it was trivial ... And yes, I am using it for the first time . I tried dealing with the DataContext.Refresh() method, but it gave me errors. How can I make the update to occur like SqlDependency (is there's such an option Read More...
|
-
Hi I do var mulige = from b in ctx.Formular_UdfyldtBlanket where b.BlanketUid == blanket.BlanketUid orderby b.Titel select b; And when I try to test for no result I would imagine one of the following: 1. if (mulige==null)..... 2. if (mulig.count()==0)... But both give the wrong result.... how do I test for no records returned from the query.... regards Jens chr Read More...
|
-
Hi, I am very much new to Linq. I have problem. I need to retrive a set of rows from a datatable with linq query as shown below Dim dt1= From c In dataTable1.AsEnumerable Where c.Field(Of String)("chrSubName").StartsWith("S") _ Select IDS = c.Field(Of Integer)("intid"), N1 = c.Field(Of String)("chrName")), N2 = c.Field(Of String)("chrSubName")) GridView1.DataSource = dt1 GridView1.DataBind() This works fine but when any of the field ("chrName" or "chrSubName") is Null for any row applicaton fires Read More...
|
-
Hi, I have a " Customer class. At a tme I need to insert 10 records. If I use " InsertOnSubmit" i need to move between Linq and my buisness layer 10 times. Is it possible to use " InsertAllOnSubmit" so that i can insert 10 records on a single call. If possible please write the code regards Sreejith Read More...
|
-
Hi, let's i have a linq query like this: from x in dataConext.Xs select new y { Id = Guid.NewGuid(), Property = x.Property } the problem is, that y's Ids will be the same in whole result set. I could go through result set and manualy set Id to new guid for every instance, but it's interesting in general how similar problems are handled? Read More...
|
-
I am new to using linq and need some help creating a Where Expression. What I would like to do is be able to query my database and display data in a gridview where the date for the record is occuring on the current day or in the future. How do I go about doing this? Thanks for the help. Read More...
|
-
I've been using linq to sql for about a month now without any issues, it's a fantastic framework. However recently i've enountered a problem i can't seem to solve. It happens when i call submitChanges() on the datacontext class. i get a System.InvalidCastException. Here the code that causes the exception Bills_PushContent contents = new Bills_PushContent (); billPaymentDb.Bills_PushContents.InsertOnSubmit(contents); contents.PushDataId = 0 ; contents.PaymentRefNum = pData.PaymentReferenceNumber; Read More...
|
-
I have recently finished most of the development on a virtual tour posting system for real estate agents and ran into a HUGE problem with the Linq To SQL designer. I created my back end data layer using the Linq To SQL designer in VS2008 and everything worked perfectly, or so I thought. Information from this data layer is mapped over to my business objects, and those objects handle all my logic, inserts, saves, and deletes. All those commands are persisted back to stored procedure functions designed Read More...
|
-
I've had a few occaisions where I would like to use an already defined anonymous type field and haven't been able to figure this out. Here is what I want to do: List Product > products = new List Product >(); var categories = from p in products group p by p.Category into g select new { Category = g.Key, TotalApples = g.Sum(p => p.ApplesInStock), TotalOranges = g.Sum(p => p.OrangesInStock), TotalFruit = TotalApples + TotalOranges, }; I have to call the sum of Apples & Oranges again on TotalFruit if Read More...
|
-
Hi all, Can I use Linq to XSD in my Silverlight app? I want to connect to a sharepoint server webservice from Silverlight. Thank you for your suggestions schorsch Read More...
|
-
I cannot connect to sql server from visual studio 2008 express. the sql server does not appear when attempting to configure new connection to data source. Read More...
|
-
Hello, I would like to be able to map a SQL query, as received by SQLServer to the originating Linq query. On SQLServer, we register all SQL queries with a duration of more than 10 seconds. We use this list to check if there are no queries to optimize. With queries that are created directly in the code, it's easy to find where the query is sent to SQLServer and to find which screen of the application is impacted. I would like to do the same with Linq queries. Is it possible to find, starting from Read More...
|
-
I have tried and tried to get what I thought would be not so tough but I am stuck. I have a single table (Car Sales) and I simply want to know how many of each of the following a salesman sold: New Vehicles Vehicle Year Colors ('Blue', 'Red', 'Green') The relevant fields from the Sales table are: SalesmanID int IsNew bit VehicleYear char(4) Color varchar(10) Ideally I would like to group by the SalesmanID and receive a count of each of the fields described above. The best I could do is this: var Read More...
|
-
I have a column of type datetime which is null in my database. When i try to retreive it i get an exception... The null value cannot be assigned to a member with type System.DateTime whcih is a non-nullable value type. plz help Read More...
|
-
I know this possible, but I can't seem to find an example. I am just trying to query to find all Customers that have at least one Order. The SQL looks like this: SELECT Customer.* FROM Customer WHERE CustomerID IN ( SELECT CustomerID FROM Orders WHERE ([Status] = 1 OR [Status]=4) GROUP BY CustomerID HAVING (COUNT(*) > 0) ) What's the LINQ equivalent? Read More...
|
-
I have a strange problem with LINQ queries. I want to have a different property name than my table column name. I believe, LINQ supports this. class [ Table (Name = "dbo.TestEmployee2" )] public class TestEmployee2 { private int m_EmpId; [ Column Attributes] public int EmpId { //get,set.. } private string m_EmpName; [ Column (DbType = "varchar NOT NULL" ,UpdateCheck= UpdateCheck .Never, Name= " EmpName " )] public string EmpNameTesting { //get,set.. } //Other Properties } EmpName column has different Read More...
|
-
Hi, I have a very large List to iterate over and pick out elements that meet a certain condition. I would like to use LINQ for this, but I have a performance problem. I want to stop after I have the first 5 that meet my criteria. In a loop, I would just "break" out of it. Is there a way to stop the query once I get my 5, or do I have to iterate over the entire list (which is considerably slower in most cases). Thanks. Read More...
|
-
First here is my code to query the db: Dim bracketQuery = From bracketCust In histTab.AsEnumerable _ Where bracketCust.Field( Of String )( "CusNo" ) = cusNo _ AndAlso (bracketCust.Field( Of String )( "Item_No" ) >= "700-003" And bracketCust.Field( Of String )( "Item_No" ) "799-339" ) bracketCount = bracketQuery.Count Dim bandQuery = From bandCust In histTab.AsEnumerable _ Where bandCust.Field( Of String )( "CusNo" ) = cusNo _ AndAlso (bandCust.Field( Of String )( "Item_No" ) >= "805-25905" And bandCust.Field( Read More...
|
-
p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in;margin-bottom:.0001pt;font-size:11.0pt;font-family:'Calibri','sans-serif';} a:link, span.MsoHyperlink {color:blue;text-decoration:underline;text-underline:single;} a:visited, span.MsoHyperlinkFollowed {color:purple;text-decoration:underline;text-underline:single;} span.keyword1 {font-weight:bold;} .MsoChpDefault {font-size:10.0pt;} @page Section1 {size:8.5in 11.0in;margin:1.0in 1.0in 1.0in 1.0in;} div.Section1 {page:Section1;} Hi everyone, I have Read More...
|
-
I have successfully managed concurrency problem in my project using timestamp field. My Concern is, we have Unique Identifier in our all existing tables. Is there any way to use Unique Identifier field for Concurrency handling instead of timestamp ? Regards Hasmukh Read More...
|
-
Help I am stuck, this is weird! After running this code, the "TestDocument" contains "First Save" and not "Second Save" like expected. Code Snippet // Test TestDataContext dc = new TestDataContext (); TestDocument d = dc.TestDocuments.First(); d.Source = "First Save" ; dc.SubmitChanges(); d.Source = "Second Save" ; dc.SubmitChanges(); Why my second "SubmitChanges()" call does not write into the database? Before calling the second "SubmitChanges()", the ChangeSet of the DataContext correctly contains Read More...
|
-
Hi, I'm researching about Linq to Entities and I'm having some doubts about composition I have 2 tables one for Persons, and the other for Profiles Suppose that a person has always 1 profile: (1 to 1) relationship Diagram On my domain I can make an asociation between both in a relationship 1 to 1, but i want to make a composition. Composition, everything would be ok but the value for the condicion for the composition it's a hardcoded string for a property so i can´t match the IdPerson from Profile Read More...
|
-
I have a recursive table with 3 levels of skills that looks like this: Skill ParentSkill Mark of course firs level is the one with parent level set to null. I need to produce a structure that would look like: Level1_Skill | Level2_Skill | Level3_Skill | Mark for example: Language | .NET | LINQ | Good in sql, I would write something like: SELECT T1.Skill AS Level1_Skill , T2.Skill As Level2_Skill, T3.Skill As Level3_Skill , T3.Mark FROM Table T1 WHERE T1.ParentSkill IS NULL LEFT OUTER JOIN Table T2 Read More...
|
-
Hi I Have this code in c# (linq to sql) if ( string .IsNullOrEmpty(RegistroArticuloOperacion.Articulo_x_Bodegas.Take(1).SingleOrDefault().AxB_Activo)) Chk_articulo_activo.Checked = (RegistroArticuloOperacion.Articulo_x_Bodegas.Take(1).SingleOrDefault().AxB_Activo) == "si" ? true : false ; else Chk_articulo_activo.Checked = true ; registroArticuloOperacion is a instance of a table articulo and apperar this error: if doesnt exist a registry this error appear: System.NullReferenceException: Referencia Read More...
|
-
Hi guys, I need your help. I'm starting to use Linq. I have some issues and I don't know how to solve them. The application has two classes communicating with database using Linq. The first one is remoting interface implementation and the second one is in the form code. Each one has a privately declared Linq to SQL DataContext (Private db As New MyDatabaseDataContext) When the first class updates values in one of the database tables, the form class gets the old values until the application is restarted. Read More...
|
-
Hi, I have two string arrays one which holds the field names and the other which holds the values. I need to create an SQL update statement using these arrays. Shown below is the code I am using to create the statement. But, in case I have a null string in the values array I ahould pass the value as NULL to the database and not as 'NULL' or '' which is what the below code does. How do I pass the NULL values as such to the command string here? string[] fields = new string[] { "Col1", "Col2", "Col3" Read More...
|
-
Small question. I currently have a Linq query that will be used to populate my Datagrid ( winforms ). But I was wondering how I could set the column headers based on metadata from that query ? Let me explain more : Assume 2 tables book and category ( each book has a category id to get a relationship between the two ) and the linq query will return the book name and category name. But how can I now get metadata from this query so that I know I'm getting the fields bookname and categoryname ? ( I want Read More...
|
-
I'm triyng to convert an application to support linq to entities and found another problem... On this app there is a form that loads a small table on a DataTable and show it on a DataGrid. There is also a TextBox for the user input some condition. As the user click on a grid's column, he can filter the data from the grid typing what he wants on the textbox example: The DataTable is loaded with Products information. If the user click on the PRODUCT_NAME column, when he type on the textbox the application Read More...
|
-
What is the "Join" and "Having" SQL analog in LINQ ? Read More...
|
-
Have datatable(dt) that's populated with Name, ID, status, etc. What I am trying to do is create a search using LINQ against this datatable. I am able to query using a name and/or ID field using below code. Dim query = From p In dt.AsEnumerable() _ Where p( "FullName" ).toLower().Contains(txt_Name.Text.ToLower()) And _ p( "LDP_ID" ).toLower().Contains(txt_ID.Text.ToLower()) Problem is that I have a third option on the search page which is a dropdown menu. The dropdown menu has 4 options. If First Read More...
|
-
Join with 2 tables hi, I want to retrieve the columns from 2 separate tables. The tables are not related directly though. Here is the join that i had written but i am unable to retrieve the data from both the tables. var query = from p in BCSDC.Programs join pbh in BCSDC.ProgramBOMHistories on p.ID equals pbh.ProgramID join b in BCSDC.BOMVersions on pbh.BOMVersionID equals b.ID join bvc in BCSDC.BOMVersionComponents on b.ID equals bvc.BOMVersionID where bvc.ComponentID == commodityID select new { Read More...
|
-
Hi All, I am new to this world of database querying and management. As such, I am exploring both new and classic working techniques. Of course I started reading through Linq, which seems to enhance my power as a new programmer, with brevity and comfort. So I scanned the net and especially this forum for answers in the performance area. Then I found Rico's blog and his vast research, yet... after reading through his five articles I am left with many questions. I'd be very appreciative for some answers Read More...
|
-
Hi, Can anyone tell me how i will pass multiple conditions for update. BomVersionComponent upbvc= DataContext.BomVersionComponents.First(e=>e.BomVersionID= 3 && d=>d.); upbvc.somecolumnname = 45; DataContext.SubmitChanges(); BomVersionComponent upbvc=DataContext.BomVersionComponents.Where(e=>e.BomVersionID= 3 && d=>d.); upbvc.somecolumnname = 45; DataContext.SubmitChanges(); after "d." intelisence is not comming for adding another condition to first method and i tried with where method also for where Read More...
|
-
This query, is meant to 'concat' ranges of records, within a specific table (text in this case). first range var query = Texts.Where(t => t.BookChapterAlineaid >= versRanges[0].TextIdFrom && t.BookChapterAlineaid && t.bookeditionid == bookEditionId); --- Concatenating or 'union all' starts here --- query = query.Concat(Texts.Where(t => t.BookChapterAlineaid >= versRanges[x].TextIdFrom && t.BookChapterAlineaid && t.bookeditionid == bookEditionId)); ERROR happens here return query.ToList(); The SQL Read More...
|
-
I'm using the Extensibility Method Definitions and ExecuteCommand to change the way I insert Products. I basically want update the product and if the number of updated rows returned from ExecuteCommand is 0, insert the product instead. I also want the identity returned so I don't receive "The database generated a key that is already in use." errors. I can do this using stored procs mentioned in this post and it works fine. http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1976377&SiteID=1&mode=1 Read More...
|
-
Hi there, I have an issue where I need to group XML elements from a sibling with one attribute up to but not including the next sibling with the same attribute. The siblings in between don't have the same attribute value--this is where I get confused. The XML is actually the output of pdftohtml's XML option. Here is a sample of what I want to have happen: Header1 Start1 Field1 Field2 Start2 Field3 Header2 Start3 Field4 Field5 Field6 After Processing: [Group=Header1] [Group=0] Start1 Field1 Field2 Read More...
|
-
Having a database table Order and OrderItem . The column OrderItem.Order (= foreign key) references the according Order.ID , so that an order can consist of many order items. I created an ADO.Net Entity Data Model in VS 2008 and created a query to retrieve specific orders (by using the order ids). The foreign key reference is stated in the data model. Problem: When I tried to read the collection of order items (by using LINQ (C#)) each order has an empty collection. It seems that the foreign key Read More...
|
-
We are looking for people that have a passion for creating rich, intuitive, integrated XML experiences and are able to drive innovation from vision to product. If you’re passionate about cool experiences for world-class, innovative tools, interested in designing new cutting edge WPF visual designers and want to work for a team that’s focused on shipping technologies and having fun, we’re interested in hearing from you. Drop us a line through the team blog or directly to me and we’ll get back to you. Read More...
|
-
p.MsoNormal, li.MsoNormal, div.MsoNormal {margin-top:0cm;margin-right:0cm;margin-bottom:10.0pt;margin-left:0cm;line-height:115%;font-size:11.0pt;font-family:'Calibri','sans-serif';} .MsoChpDefault {;} .MsoPapDefault {margin-bottom:10.0pt;line-height:115%;} @page Section1 {size:595.3pt 841.9pt;margin:70.85pt 3.0cm 70.85pt 3.0cm;} div.Section1 {page:Section1;} Consider the following tables: ORDER_DETAIL ID PRODUCT_ID VALUE PRODUCT ID NAME Now if I want to get all products that do not exist in ORDER_DETAIL Read More...
|
-
Subject tells everything.. Please help me out.. Read More...
|
-
Hi All, What is the best practice to design to datacontext? Let us assume, I have a database with 200 tables? Should I create just one datacontext? a nd instantiate for each unit of work? or should I design a seperate datacontext for may be related tables? Could you please share your views? Thanks Hari Read More...
|
-
Hello All, Sorry for the lengthy title, tried to squeeze as much details as possible up there ;) Anyhows, my questions is... Assume I have made a dbml file for my database. I've scouted all my basic tables and recieved my basic types, I've got customers, employees, manager, EmployeesToMangaers and so on already configured for me by Linq. Now I want to build some basic stored procedures, you know... like: "Get Managers Employees". Now once I build it, and run it from my c# program thanks to LINQ I Read More...
|
-
hi, Can any body give same code to me for checking duplicate rows in insert mode using linq. when i click save buttton to insert already one record is ther in database iam inserting same data again then how i find that duplicate rows (unique) using linq. Read More...
|
-
Hi, public void UpdateComponent(IQueryable IQComp) { try { foreach (DComponent Co in IQComp) { Co.IsBOM = true; } BCSDC.SubmitChanges(); } catch (Exception e) { MessageBox.Show(e.ToString(), "Error"); } finally { } } can any body tell me how i will insert that ISBOM column value as true . Read More...
|
-
We are in the process of re-engineering an n-tier large scale application. We are considering LINQ to SQL and Data Access Application Block (MS Enterprise Library) to create Data Access Layer. The key decision factors are Performance, Maintainability and Productivity. Here are our findings: Performance: The performance of LINQ to SQL is slightly lesser than DAAB approach (for our test scenario). In few cases LINQ to SQL is better than DAAB! Maintainability: LINQ to SQL is the clear winner when comes Read More...
|
-
Content controls are an effective way to add structure to word processing documents. You can write a very small LINQ query to retrieve the contents of content controls. This topic in Office Online provides more information on content controls. In an upcoming post, I’m going to show how you can write a small test harness to test code that is embedded in documents. This is particularly useful, say, to a program manager who has written a specification that contains a lot of code that shows how to use Read More...
|
-
I am experimenting with listview and linqdatasource to see if it will work as a way to write a quick simple application. I am running a problem with one table. As much as possible I am using pure generated stuff from the toolbox wizards. I use SQLMetal to generate the DBML so I don't have to worry about changes in the database. I use partial classes to supply any extra bit of logic to the entities. In clue or suggestion would be appreciated. If I had to guess I'd think it was due to the related tables Read More...
|
-
Hello, I'm going crazy with the following query ! I want to retrieve my tags per category. First, I want to know how many tags a category has. I tried the following query: var l = from c in RootElement.Descendants("image") let filenameDb = (string)c.Attribute("file") from d in photos let filename = d.Path where filename == filenameDb select c.Element("options") into AllOptions from e in AllOptions.Elements("option") let category = (string)e.Attribute("name") let Tags = (from e2 in AllOptions.Elements("option") Read More...
|
-
I'm trying to use the Select method on a DataGridView to query the SelectedRows, but the Select method isn't available. i.e., I'm trying to write code like: Code Snippet var myRows = dgv.SelectedRows.Select(lambda function); where dgv is a DataGridView. While the Select method isn't available, I can write code like this: Code Snippet var myRows = from DataGridViewRow row in dgv.SelectedRows where true select row; Why can't I use .Select instead? What makes it possible to use the .Select method with Read More...
|
-
Hi All, I have a service that is returning to me an ObservableColleciton of 1000 Customer records. I am also getting another ObservableCollection of customer order data for all 1000 customers. What I want to do is iterate over each customer and using LINQ select the order details that apply to them and then assign them to the CusotmerOrders property on the customer class. The problem I have is that given the following query var dOrders = from p in custOrders where p.CustID.Equals(cust.CustID) select Read More...
|
-
I have the following in vb.net dim number as integer=300023 //just an example Select case number Case 490300 To 490301 Case 490310 To 490334 Case 490341 To 490394 Case 490395 To 490399 Case 490400 To 490499 Case 492800 To 492899 Case 498700 To 498799 //Dosomething Case 308300 To 332999, 352800 To 358999 //do something else end select Unfortunately c# cannot the above and the equivalent is ugly if else statement. I have a lot of numbers and the function is becoming unreadable. Is there a way i can Read More...
|
-
How can i convert this SQL statement to Linq to SQL. SELECT * FROM dbo.Adr LEFT OUTER JOIN dbo.Users AS u ON u.SystemUserId = dbo.f_SearchUserGuid() WHERE (EXISTS (SELECT 1 AS exp1 WHERE (dbo.Adr.OBUId IN (SELECT SBId FROM dbo.BU AS b WHERE (BId = u.BUId))))) Please help. Thanks Gisela Read More...
|
-
The Dynamics CRM duo are at it again. Ben Riga and Girish Raja have put together an interesting video in which they talk about integration of Office with Dynamics CRM and Office Live Small Business (based on SharePoint). Office Live Small Business is a super way to enable collaboration with customers. Their demo takes great advantage of the web services that are exposed by Office Live Small Business. Worth watching. Read More...
|
-
How to check condition from one LINQ Query Value to Another LINQ query? i am taking DocId from first LINQ query which is matching with second LINQ query. but i am getting error. first LINQ query is working fine and taking value. when i match with second LINQ query, here only i am getting error. how to match condition with local veriable to LINQ? Here i have given my code. var CheckCalendar = from resourceAvailabilityHeader in dwbContext.RESOURCEAVAILABILITYHEADER where (resourceAvailabilityHeader.ResourceCode Read More...
|
-
Raw data for a LINQ query doesn’t always come in the form you want. Recently, I had some data like this: string [] source = new [] { "EW" , "Eric" , "8:00" , "DW" , "Dave" , "9:00" , "JA" , "Jim" , "8:00" }; You want to transform the above collection of strings into a collection of anonymous objects that are easier to work on, so you need to write a query that operates on groups of three. To solve this problem, you can take advantage that the Select extension method has an overload that passes an Read More...
|
-
You can use lambda expressions to write an event handler, even for classes that predate C# 3.0 and the latest version of the framework. This can shorten your code, and make it easier to read. For example, the code to validate an XML tree using an XSD schema takes an event handler because it may return multiple errors or warnings for a single validation pass. An easy way to write this code is as follows: using System; using System.Linq; using System.Collections.Generic; using System.IO; using System.Xml; Read More...
|
-
Sometimes you need to find the duplicates in a list. I’m currently developing a little utility that tests code in a word processing document (to be blogged soon). Each code snippet in the document has an identifier, and one of the rules that I’m imposing on this code testing utility is that there should be no duplicate identifiers in the set of documents that contain code snippets to be tested. An easy way to find duplicates is to write a query that groups by the identifier, and then filter for groups Read More...
|
-
Hello, This is about "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext". I have read a lot of threads and blog pots about this, but I haven't been able to pass this issue. I have an ASP.NET project and I keep an entity in Session, so that I can add other entities related to my entity. In the end, I want to persist all by calling InsertOnSumbit for the first entity. Here is the code: Code Snippet BusinessLayer.admin.BillEntry Read More...
| |
|