|
|
July 2008 - Posts
-
Hello, How would I write a LINQ that looks like this in T-SQL select g.GroupId, g.GroupName, (select count(UserId) from UserGroup where GroupId = g.GroupId) as GroupMemberCount, (select UserId from UserGroup where GroupId = g.GroupId and UserId = @UserId ) as GroupMemberId from [Group] g This query basically returns groups with number of members in it. Notice the line in red? I basically need to find out weather the currently logged in user already is a member of that group or not. I have my dbml Read More...
|
-
To share connection strings with our existing architecture, I want to use the dbml fragment: And that works great; the tooling generates code that uses the shared connection strings via ConfigurationManager. However, if I go into the visual designer and do anything (toggle a field nullable and back again), then when it saves the dbml it trashes the element, resetting it to AppSettings and the project-specific SettingsObjectName. This is very irritating, as the WebSettings mode works a lot better Read More...
|
-
ZDNet Asia recently interviewed Oliver Bell, Microsoft Asia-Pacific's regional technology officer. The story mentions Oliver's blog post on the value that custom schema support adds to the format. I can attest that I've had several conversations recently where customer's problems were solved by either custom XML parts that are bound to content controls, or embedded custom schema support. In addition, Ian Blackley, sales engineer at TX Text Control, comments on the momentum of Open XML: "We expect Read More...
|
-
Does anyone know how LINQ to Objects works internally? Will it do two loops for a .Where and a .Select if a query is written as: from String s in list where s.Count > 5 select s.ToUpper() or is it smart enough to combine it into 1 loop to improve performance? Read More...
|
-
Hi, Sometimes I need a data like below: NorthwindDataContext db = new NorthwindDataContext(); DataLoadOptions loadOptions = new DataLoadOptions(); loadOptions.LoadWith(c => c.Orders); loadOptions.LoadWith(o => o.OrderDetails); db.LoadOptions = loadOptions; foreach (Customer item in db.Customers) { // needed data. Console.WriteLine(item.ContactName +" Order Count"+item.Orders.Count+" "+ item.Orders[0].Order_Details.Count()); } What is happeng here is that Orders are prefetched with customer. But, Read More...
|
-
Hi, i have a DataGridView that is popoulated (using linq) from a database (a typical clients table). So, let's say that the data is presented to the user and he decide to filter them with the City column = "London". To make things simple, i let him click in a cell of the city column that contains the word "London" and then to click a button so the DataGridView can be filtered and display only these rows that the City column contains this value. So i am doing it like this: var query = from DataGridViewRow Read More...
|
-
This week, I’ve been attending a gathering of Microsoft technical sales professionals. In one presentation, I heard the following opinion (paraphrased): “The most important pillar of SharePoint is content management. This is the core value proposition of SharePoint. It is what is driving sales.” In another one, I heard: “The most important pillar of SharePoint is social computing and collaboration. This is what is driving its adoption.” I think that what this means is that content without collaboration Read More...
|
-
Hi, I have two tables workflows and workflowTasks both having workflowname column as common .Using LINQtoSQL i have created entity class for these tables and created relationship between them for workflowname using association attribute. Using this relation i am binding the grid in hierarchical view. i want to show workflowname column in parent row alone and not in child row, so while inserting a new row in child how can i insert workflowname from parent entity class into child table. Regards, Sundar Read More...
|
-
Hi, I have been reading how inheritance works in LINQ and haven’t figured out how to make an update to the value that is used as its discriminator value. I have been using the employee example in David Hayden's posting " LINQ To SQL Discriminator Column Example - Inheritance Mapping Tutorial " . I changed Employee’s “Inheritance Modifier” to (None), so I have the following: Class Layout [ Table (Name= "dbo.Employee" )] [ InheritanceMapping (Code= "2" , Type= typeof ( CommissionedEmployee ))] [ InheritanceMapping Read More...
|
-
How do I create hot keys in a CAB application? I thought of treating the hot keys as commands but all examples I saw for adding command invokers referred to menu items. I would like to add command invoker that will respond to a key pressed any where in my application Read More...
|
-
Pranav released another drop of Open XML Diff . There are a couple of bugs fixed. Read about it here. This tool is a developer's friend. When I'm writing code to generate an Open XML Document, I know how I want the document to render in Word, but am unsure about which element or attribute to tweak. So I save a copy of a doc, modify it, save it again, and compare the two, it lets me know what I want to control programmatically. Read More...
|
-
Dim query = (From order In fth.AsEnumerable Where order.Field(Of String)("vocab") = strrow Select New With {.s = order.Field(Of String)("subhead").ToString, .i = order.Field(Of String)("item").ToString}).ToArray Dim queryb = (From sg In fi.AsEnumerable.AsQueryable Where sg.Field(Of String)("subhead") = o.ToString Select New With {.h = sg.Field(Of String)("subhead").ToString.AsQueryable, .m = sg.Field(Of String)("item").ToString.AsQueryable}).ToArray I've tried to intersect the above two queries but Read More...
|
-
Hi, Here is my scenario: I have 3 tables: Person, Agency and AgencyPerson to represent a m:m relationship. I populate a listbox with Person.AgencyPersons. Add a Agency to the collection using this code: Code Snippet AgencyPerson agencyPerson = new AgencyMemberNatPerson();agencyPerson.Agency = agency; agencyPerson.AgencyId = agency.Id; agencyPerson.PersonId = person.Id; agencyPerson.Person = person; to remove it, i simply remove it from the Person.AgencyPerson.Remove(...) Scenario: I add a agency, Read More...
|
-
hello, i am quite new to LINQ and facing a problem with LINQ to SQL. I hope that anybody can give me some advises how to handle this issue. I am developing a n - tier Solution where i want to seperate the LINQ queries in an Data Access Layer. Querying is working... just updating the db (SQLServer Express) is not. The code is following: static DataContext dc = new DataContext ( ConfigurationManager .ConnectionStrings[ "DATABASE" ].ConnectionString); public static Boolean SetOnlineStatus( Guid userid, Read More...
|
-
Hello everybody, Thanks for taking the time to read this. How is it possible to set the Where property of a LinqDataSource to include a subquery? If i use this line of code: Code Snippet ldsTasks.Where = "DeptID IN (SELECT DeptID FROM PersonDepts)" ASP.NET returns: Expression of type 'Boolean' expected If I test this line of code: Code Snippet l dsTasks.Where = "addedby=" & id & " or deptid in (select deptid from persondepts where personid=" & id & ")" ASP.NET returns: Operator 'or' incompatible Read More...
|
-
Hello, Let say that i have in datacontext a class called Product It's possible to add new methods or properties at Product class and than used them in a linq statement. something like this Code Snippet public partial class Product { public int NewProperty { get {return this.ID*2;} } //or public int Property() { return this.ID*2; } } .............. var q=from item in context.Products where item.NewProperty==2 select item ; I tried with expression functions delegate but i didn't succeed. Read More...
|
-
hi, i'm trying to write a projection ProductView. public class ProductViewHelper { private Design _design; private Asset _asset; private List _designText; private List _designImage; etc.. } Here is the Linq i have so far, i'm not getting much love from the intelligence. My question is how do i populate a collection within a projection var query = from d in db.Designs join a in db.Assets on d.Id equals a.DesignId select new ProductViewHelper(new Design(d.Id, d.Title, DateTime.Now, d.PreviewImage), Read More...
|
-
I try to show the data from entity model and display them in datagridview1. i got this error: The underlying provider failed on Open. try { using ( AdWorkEntities entities = new AdWorkEntities ()) { Customer eph = ( from bp in entities.Customer.Include( "Customer" ).Include( "Customer.CustomerID" ) where bp.CustomerID > 0 select bp).First(); dataGridView1.DataSource = eph; } } catch (Exception ex) { throw ex; } } Read More...
|
-
Hi, i'm working on building data layer having XML documents for storage like : Code Snippet 1 First item 12.32 ... So in my data layer i want to implement methods : GetAll, GetByName, GetByPrice,... so far this is the scenario i used : Code Snippet class ItemDal { private static IEnumerable GetCore() { XDocument xml = XDocument.Load("dataItems.xml"); return ( from row in xml.Descendants("item") select new Item { ItemID = (int)row.Element("id"), Name = row.Element("name") != null ? (string)row.Element("name") Read More...
|
-
I have a query in LINQ like this: Code Snippet var organisations = from o in _cx.Organisations join oa in _cx.OrganisationAddresses on o.RecID equals oa.OrganisationID join ot in _cx.OrganisationTypes on oa.AddressTypeID equals ot.RecID join a in _cx.Addresses on oa.AddressID equals a.RecID select new { o.RecID, o.Name, o.Created, ot.Description, a.Street, a.Number, a.NumberAddition, a.Zipcode, a.City }; Now how would I get this into a workable Lambda expession? I need to do the upper query but with Read More...
|
-
Hi, here is the situation : - a table, say "tableA", that contains a certain number of fields, is mapped to a class "A", - a table, say "tableB", contains some extra attributes that semantically belong to table "tableA", but "tableA" cannot be extended, in order not to break existing code. The goal is to create a class, say "ExtendedA", that contains all the attributes of class "A", and some attributes coming from table "tableB", and map this class to the database without modifying neither "tableA", Read More...
|
-
I am looking for recommendations/solutions on LINQ using too much memory. Performance over 95% Thank you! Read More...
|
-
This has probably been discussed before, but I've been unable to find anything via search. I have a proc that I have dragged to the method pane. Everything works ok. I modified the proc on the server and return to the Linq to SQL designer. I understand that I must delete the existing "method" and redrag the proc. I'm ok with that, but the code generator is not picking up on the fact that my proc now returns an additional column. That was the only change to the sproc on the server - add 1 extra column Read More...
|
-
This is old story and I have used parts of it over the last three years to show how LINQ lets you navigate from relational to object or object to XML etc. But for a forthcoming demo, I had to some quick code today and it looked like it might be worth sharing. So here it is ... A little background first: I need to show a 3-tier app where the mid-tier can use a variety of DALs (not just LINQ to SQL ). A good way to show that is how you can use POCO classes with some extra info. An easy way to populate Read More...
|
-
I edited this because I am at a new point I'm trying to save a new row into my Orders table. This table has several foreign key constraints. CustomerID, ContactID, AddressID, OrderNotesID, OrderDatesID, OrderStatusID. Each linked to a table of the name (minus ID). After overcoming many hurdles I got to the point where it was actually generating SQL, but I find with the logging tool that it is trying to insert a new Customer and insert a new Contact. Obviously I don't want it to even attempt to do Read More...
|
-
Hello everyone. I have something I need help on. Basically, I have functions called CreateCustomerProject, CreateCustomer, CreatePlant, etc, to convert a LINQ to SQL class to one of my Data Model classes I need these functions because there may be multiple select new CustomerProject{...} blocks and I do not want the same code for class mapping more than once. The code below always works: public IList GetAll() { return service.GetCustomerProjects().ToList(); } This throws an error: "System.NotSupportedException: Read More...
|
-
Hi there, I have 3 XML document files as below, how can i perform LINQ query to list name of all doctor in any rooms that have patient with the most recent startdate, the result will have one or more doctor's name, as below, the result should have two doctor's name. Any help would highly appreciated, thanks in advance. doctor.xml ======= John Mckcay c001 Janet Maus c003 Ernest Felts c004 c005 patient.xml ======== location1 50000 2005-01-12 2005-12-12 location2 120000 2008-02-22 2008-09-31 location3 Read More...
|
-
Hello Everyone, I've got an XML field in my SQL Database, and I've loaded the field using LINQ to SQL. (i.e. I have an XElement for the field). I want to use LINQ to XML on this field but when I try to do so I get an error as below, Code Snippet Method 'System.Xml.Linq.XElement Element(System.Xml.Linq.XName)' has no supported translation to SQL. A sample of my code is below (xmlDataField is a XMLData field in a table called myTable in my SQL Server 2005 Database), Code Snippet MyDataContext myDataContext Read More...
|
-
An arraylist is analagous to a dynamic array. Do I have that correct? With that assumption, I have created a List with 3 "columns" in each record and about 150 records. No problem so far. Now I need to go back to each record and add another field, lets call it "Unit Price". 1. Can I do this? 2. If so, how do I address the specific record that I want and add the column and its data? Thanks. This one has me stumped. Read More...
|
-
Antonio Zamora from Staff DotNet has posted something pretty cool - firing off a PowerShell script from C# to apply a consistent style to multiple Open XML documents. This is an interesting way to take advantage of the PowerTools for Open XML . Read More...
|
-
first thanks for a very good forum.... Is there anyone that can tell me what wrong widh my table or my Linq-code ? i have a table like this TimeID int Unchecked year varchar(50) Checked mnd varchar(50) Checked brukerID int Unchecked Dato datetime Checked Inn float Checked Ut float Checked Inn2 float Checked Ut2 float Checked SumTid float Checked and some data in this table : timeID,year, mnd brukerID Dato inn ut inn2 ut 2 SumTid 3 2008 7 3 01/07/2008 00:00:00 6,3 18 12 12 NULL 4 2008 7 3 19/07/2008 Read More...
|
-
Hi there, I have 2 xml file as below, I use outer join (not sure this is the best way) but not success. Purpose: find all information of person including pid, name, area who are not work in the cleaning jobs. persons.xml ======== John North William South Mary South Jason South cleaning.xml ========= p001 Clean windows p001 p003 wash the clothes Below is incomplete code and sure correct or not, any help is highly appreciated. XDocument cle = XDocument.Load(@"..\..\cleaning.xml"); XDocument per= XDocument.Load(@"..\..\person.xml"); Read More...
|
-
The response to my previous blog post has been very interesting to me. And it has, to a very large extent, matched my own experience. I have seen four basic scenarios where folks use LINQ: Using LINQ to Objects (and LINQ to XML, which is really just LINQ to Objects), primarily using the extension methods, and the so-called ‘method syntax’. This really is a great scenario. When I really understood it, it blew my mind. I believe it leads to the possibility of “speed-reading” code – see below. Using Read More...
|
-
Hi, here is the general architecture : - the client side interface is an AJAX application that sends an XML stream to the server, the stream may look like : Code Snippet 1 2 - the server receives this stream and has to convert it to business objects in order to manipulate them through business interfaces, - the server persists these business objects to the database. For the moment the business objects are mapped to the database via LINQ by annotating the fields and classes this way : Code Snippet Read More...
|
-
My windows application has to work with 3 databases(Sybase,Sql Server and Oracle). But I do not need to connect to all 3 at the same time. The application has to use only one database at a time , depending on what database is chosen. I would like to write database agonistic code so that it can be used for all the three databases . LINQ seems to be a good solution as I can formulate queries against the model instead of writing raw SQL queries.Will LINQ to SQL work in a scenario like this? If it does Read More...
|
-
I am taking the results of a XamlWriter and using the parse method to read it into an XDocument. When the xml is parsed it adds spaces between tags. BEFORE: Here is some text AFTER PARSE Here is some text I have tried playing with the LoadOptions during the parse but nothing seems to stop the addition of the spaces. Any ideas? Aaron Read More...
|
-
like serious in linq ? SELECT ProductName, SupplierID, CategoryID, Discontinued, (SELECT CategoryName FROM Categories WHERE (CategoryID = Products.CategoryID)) AS CategoryName, FROM Products thanks, and greetings to all Read More...
|
-
Hi, I'm having troubles with DLINQ since three days. Actually I can't insert, or even delete (the basics) data in the database. I followed that tutorial : here Here are my classes: Category { ..... } Type { EntityRef Category EntitySet Properties } Property { EntityRef Type } Here is how i proceed the insert: ... Context db = Context.getInstance(); /// I use a singleton to have an unique instance db.Properties.InsertOnSubmit(newprop); db.SubmitChanges(); I do the same for saving Types... then I get Read More...
|
-
I'm new to Linq and I'm just trying to setup a class that represents a simple database table and then query it. My code looks like this: Code Snippet OdbcConnection conn = new OdbcConnection(connInfo.ConnectionString); DataContext db = new DataContext(conn); Table table = db.GetTable(); IQueryable query = from header in table where header.FieldName == "Approval" select header; foreach (HeaderFieldLinq header in query) { Console.WriteLine(header.FieldName + "\n"); } When I get to the foreach (when Read More...
|
-
I had an interesting conversation with my nephew the other day. He is a very bright CS student working as a summer intern at a software company (not Microsoft). He is programming in C# using Visual Studio 2008. I asked him if developers at his company were using LINQ, and he said, "No, that the folks in charge had basically forbidden it, because no one understands it." Visual Studio 2008 has been out for over a year, but I know that a fair number of competent developers have not devoted the time Read More...
|
-
I have following simple XML document, how can I find the country that has the most staff member using LINQ to query XML as below data in ASP.NET 3.5, thanks in advance. staffs.xml ======= Jason US 3823733 Fiona 673733 Terry Japan 3247333 William US 38372944 John US 3746364 Read More...
|
-
Can anyone point me to a good resource on working with the records themselves? More specifically consider: Code Snippet var queryCust = from c in dc.Customers select c; With queryCust I can set a DataGridView.DataSource, or iterate through the records and set controls to a specific element in Customers but how do I take a single record query like this: Code Snippet queryCust.First() for instance and iterate through the elements of the record and get the element name and the value of that element Read More...
|
-
This is required since I have to use dynamic tables whose columns are dynamically changing and i use stored procedures to access data from these tables. Any solutions? Read More...
|
-
I have a custom permissions table for my application. These permissions list whether a specific Role or user is allowed to execute a specific process in the application. What I am trying to do is pass in a string array of all the roles a user belongs to, then for each role in the list add them to the LINQ Where statement. Code Snippet Public Function GetPermissionsForRole( ByVal Roles() As String ) As IEnumerable( Of Permission) Dim p = From c In Context.Permission _ Where c.Role = True 'And c.Name Read More...
|
-
Gentlemen, I have generated a Linq List which contains about 130 or so records. Each record contains a center code and it's postal (Zip) code. I also have a SQL DB and table which provides the longitude and latitude of all postal codes. I am trying to iterate through the list, extract one record at a time and then run its zip code by the database to obtain its gps coordinates. I can build the list but the second "foreach" continues looping through the same record. I have tried nesting the second Read More...
|
-
As always, forgive me my bad english... Consider the follow: I have in my application a singleton object ("AppInfo") that holds some important data. All my tables have a field "USER". I create a property on AppInfo that once accessed, create (if doesn't exist yet) a instance of the entity "USER" or simply returns it if it was already created before. Now, on my application when I need to save something, lets say an order: Entities context = new Entities(); Order order = new Order(); order.code = 1; Read More...
|
-
This post presents a custom application page in SharePoint that uses Open XML, the Open XML SDK and LINQ to XML to accept revisions, remove comments, and remove personal information from an Open XML word processing document. The following 45 second screen-cast demonstrates the code presented in this post. Video: Using Open XML with SharePoint An approach that has interesting possibilities would be to create SharePoint workflows that query and modify Open XML documents. For example, you could write Read More...
|
-
What are people doing when the need arises for an encrypted column containing sensitive data such as SSN, credit cards, passwords, etc? Some ideas I've had are: * Using SQL Server column encryption. I want to stay way from this if at all possible. * Use partial class and override the OnChanging methods to modify the value before it gets inserted into the db * Putting the encryption/decryption in the BLL - The application must do the encryption before passing to LINQ-to-SQL class and decryption before Read More...
|
-
Greetings, I know it may be the 1000th time that someone complain about performing insert and update operations using the DataContext class, so please if anyone knows a resource that gives detailed description of how to do them, I'll be grateful to be informed of it. In my ASP.Net projects, I knew how to perform insert, update and delete operations using the DataContex, but my problem now is with windows forms applications. The problem arises from that I use controls bound to the entity objects loaded Read More...
|
-
Hi there I have the following SQL query and I need it as a LINQ statement: Code Snippet SELECT s . id , t . translation AS transSalutation , t2 . translation AS transLetterSalutation FROM (( madSalutation s LEFT JOIN ( SELECT * FROM setTranslation ) AS t ON s . TranslationIDSalutation = t . TranslationID ) LEFT JOIN ( SELECT * FROM setTranslation ) AS t2 ON s . TranslationIDLetterSalutation = t2 . translationID ) What is the right syntax to have 2 LEFT JOINS (each with a SELECT *) in my LINQ statement? Read More...
|
-
I'll try to be as concise as possible about the problem I'm having: Background: VS2008 (SP1 beta) .NET 3.5 I'm developing a project utilizing a local SQL Express database with LINQ-to-SQL In my BLL class, I have a static reference to the LINQ data context, like so... Code Snippet public static taddbDataContext taddb = new taddbDataContext (); Then in my subclasses and methods, I simply reference the taddb object and everything works fine, here is an example: Code Snippet public static tad_Game GetGame( Read More...
|
-
Hello, I have some table with two fields - id (int) and name (nvarchar). I create dbml for this schema. After that I create data context, get from table one item and close it data context. I have some offline-item. After that I change it item and create new data context. To apply changes from my offline-item I try to attach it item to context and receive challenge: "An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not Read More...
|
-
I use the Linq technology to read an XML file, but I have a problem when I try to search something in it. I would like to know how can I use something such as the "like operator". var parameters = from param in xferDoc.Descendants( "parameter" ) where param.Attributes( "code" ).Contains(searchString) orderby ( string )param.Element( "description" ) select new { code = param.Attribute( "code" ).Value, description = param.Element( "description" ).Value, unit = param.Element( "unit" ).Value }; I read Read More...
|
-
Hi, After reading a few threads on this forum, I got that we cannot do explicit bulk inserts from LINQ to SQL. So, in absence of bulk inserting, what would you recommend as its optimal alternative on VS2008Pro+SQLServer2005? Thanks in advance. Read More...
|
-
When I change an XElement field in a Linq to SQL class and call SubmitChanges on the data context, it doesn't update. Linq to SQL seems to just flat out ignore XElement's change notifications. I tried a workaround where whenever the property changed I would null the XElement field and then set it again, but that doesn't work either. Is this a bug? Are there any viable workarounds? Thanks in advance, Rei Read More...
|
-
I have the following code that calls the TE_Roles linq function on the GerRolesDataContext class bool IsAttorney; bool IsSecretary; bool IsTextEditor; GetRolesDataContext db = new GetRolesDataContext (); var sproc = db.TE_Roles( "123456" ); foreach ( GetRolesClass GetRole in sproc) { IsAttorney = GetRole.IsAttorney; IsSecretary = GetRole.IsSecretary; IsTextEditor = GetRole.IsTextEditor; } The stored procedure that gets call only returns one record. Instead of using a foreach loop, I wanted to assign Read More...
|
-
Hi all, I had an IQueryable custs, a Customer cust, a CustomerComparer custCp which implements IEqualityComparer 1. when I call custs.Contains(cust,custCp) I got an exception: Unhandled Exception: System.NotSupportedException: Unsupported overload used for query operator 'Contains'. 2. when I call custs.AsEnumerable().Contains(cust,custCp) it worked. I checked the definition of the two: public static bool Contains(this IQueryable source, TSource item, IEqualityComparer comparer); public static bool Read More...
|
-
This is not specifically a Linq question but since I am quite enamoured with Linq, I try to use it for everything. QUESTION: I gather several "rows" of data from a Linq to SQL query. Each "row" contains four columns. I do not know the number of "rows" at the creation. Two of the columns are string and two are doubles. Right now I cast the doubles to strings prior to storing them in an array but declaring a fixed length array seems dangerous and I do not know how to declare a dynamic array (yet). | |
|