|
|
December 2007 - Posts
-
How do I deal with image datatype in linq. I am trying to add and retrieve images from a DB table and I am getting this error with a straight conversion of my old code. The class that mapps to the image table is expectins a binaary type instead of a byte array Value of type 'System.Data.Linq.Binary' cannot be converted to '1-dimensional array of Byte If Not (image Is Nothing AndAlso image.imageId > 0) Then context.Response.Clear() context.Response.BufferOutput = False context.Response.OutputStream.Write( Read More...
|
-
Is SQL2005 limited to only using the 2.0 framework? Or can it also use 3.5 framework objects as managed stored procedures? If not, is this a permanent condition or will that functionality be added in a SQL 2005 service pack? Read More...
|
-
The issue is shown in numerous articles, which can be found by searching the internet for keywords " dataloadoptions select count ". For example, first hit on Google is this article: http://www.scip.be/index.php?Page=ArticlesNET04 We can see that this code: Code Block NorthwindDataContext dc = new NorthwindDataContext() DataLoadOptions options = new DataLoadOptions(); options.LoadWith(e => e.Orders); dc.LoadOptions = options; var customers = from cust in dc.Customers where cust.Country == "UK" select Read More...
|
-
Hello, Trying to do what I think is simple, but the SQL output generated by Linq is messy. I want to do this: SELECT SUM ( Goal ) as Total FROM Goals WHERE GoalType = 2 To add that where clause, I seem now seem to need a Group by in Linq. The result is pretty nasty: SELECT [GroupBy2].[A1] AS [C1] FROM ( SELECT cast(1 as bit) AS X ) AS [SingleRowTable1] LEFT OUTER JOIN (SELECT COUNT([Project1].[C1]) AS [A1] FROM ( SELECT cast(1 as bit) AS [C1] FROM ( SELECT [Extent1].[Status] AS [K1] FROM [dbo].[Goals] Read More...
|
-
I having trouble getting this query to work: Result r = from tick in elapsedTicks orderby tick select tick into orderedTicks let goodData = ( from orderedTick in orderedTicks select orderedTick).Skip(skip).Take(take) select new Result { Average = goodData.Average()/ Stopwatch .Frequency, StandardDeviation = Math .Sqrt(goodData.Select(n => Math .Pow(n - average, 2)).Average()) }; What I'm trying to do is take an unordered array of StopWatch tick counts (ElapsedTicks), order that array, throw out the Read More...
|
-
Hi, I would like to have a single static datacontext for my web application. Basically, I would like to keep all the data that is fetched by the datacontext in cache and all updates done through one datacontext so that everything remain in memory. Can I use a static DataContext ? Is it possible and feasible ? There is no chance that two users will be updating the same row. In fact, updates to the database are very limited and it is mostly a read application. Do i need to use the singleton pattern Read More...
|
-
Hello, LINQ has been RTM recently and I am looking for some feedback about LINQ production readiness for enterprise applications. Is the product stable enough? Are there performance issues? Known issues or bugs? We're looking into using LINQ for an application with half a thousand views, queries and tables. Any feedback would be greatly appreciated. Thanks Sami Read More...
|
-
How does one query for a range of values in Linq? If my SQL query is something like select foo, bar from myTable where beginDate > myBeginDate and endDate how do i represent that in my query expression? thanks. CIS Read More...
|
-
Hi, Is it possible to override Join extension with our code inside of it? Because I'm stuck in develop this join query for my custom linq provider. please help... Thanks Read More...
|
-
Hi Guys! Advance Happy New Year! Are there anyway that I can retain all the modification that I have done in the .dbml.designer.cs file? I usually rename all the method and entity names and sometimes redo a method if a stored procedure was interpreted wrongly. Everytime I try to drag a new stored procedure into the dbml designer, everything gets regenerated again :( Thanks, Enzo Read More...
|
-
In SQL queries it was possible to write a function which would take column names and search values as parameters to a method and then construct and execute the query at runtime. This made it possible to write generic base classes for data layer objects which could be very easily tailored to Viz following : Function GetMembers(fieldname as string, value as object) Dim sql as string = "SELECT * FROM " & me.tablename & " WHERE " & fieldname & "= " & VALUE.TOSTRING mycommand.text = sql 'execute command Read More...
|
-
Hi, While testing LINQ i tried to use it with a WPF Application created with Visual C# Express 2008. I've done these simples steps : 1) Create Project 2) Save Project 3) Add a new SQL Server Express 2005 Database 4) Create a table inside the database 5) Link it with a "LINQ TO SQL Classes" object 6) Try to write up this simple query Code Block var ris = from u in Table1 select u; it ALWAYS come up with this error Error 1 Could not find an implementation of the query pattern for source type 'oGameS.Table1'. Read More...
|
-
Can any one tell me How to do Linq to sqlserver with WpfBrowserApplication Thanks in advance Read More...
|
-
See the comments plz. from c in Customers where c.CustomerID.StartsWith("P") join o in Orders on c.CustomerID equals o.CustomerID into sr from x in sr.DefaultIfEmpty() select new { CustomerID= c.CustomerID, OrderID = x == null ? -1 : x.OrderID, // This is OK. I thought this is the only way to safely access OrderID. Test = (int?)x.OrderID // But this works too. How does this work ok when x is null? } Read More...
|
-
1) Is Linq "set based"? Why or why not? What are the set and/or catagory theory roots. Any paper? 2) How do the functions map to the relational algebra? Anything functions missing? 3) Would linq be able to do set-oriented programming on relational data directly (no tsql middle man) in the abstract? Besides actually implementing it, is there anything in linq model that would prevent this? TIA w Read More...
|
-
Greetings, question on best practices and design: i have a number of functions within a class that pass around the result set returned from my datacontext class. My goal was to execute a single broad query, then have the middle tier manipulate the data as necessary using further linq expressions. The purpose being to minimize the noise to the DB as i'm dealing with large sets of data for example: Code Block private void MonthlyButtonClicked( object sender, RoutedEventArgs e) { //report object MTPSReport Read More...
|
-
Not sure if this is the right place for this question. I'm working on a data driven Window. I need to execute a bunch of stored procedures. Each sproc is available via the DataContext object. My window knows the name of the sprocs, but since it's data-driven I can't hard-code their execution. For example, the hard-coded approach would be: DataContext db = new DataContext(); System.Data.Linq. ISingleResult Plan_WebOrdersResult > results = db.Sproc1(); In my case I have: DataContext db = new DataContext(); Read More...
|
-
Greetings. I have a simple group and sum as follows: Code Block var transforms = from f in ReportData group f by f.PhaseName into g select new { Phasename = f.Phasename, totalDocs = g.Sum(f=>f.TotalDocs) }; however every time i compile, i get "the name f does not exist in the current context. What gives? am i missing something. i'm using f in the lambda expression on the next line without issue. Thx. CIS. Read More...
|
-
I've got an SP which queries a temp table but the return type is always INT. Is it possible to rewrite my select statement so that it can create a return type in LINQ to SQL? The SP is basically like this: SELECT col1, col2 FROM I read that using SET NOCOUNT OFF would work but unfortunately it does not. Thank you Read More...
|
-
I'm running Visual Studio 2008 9.0.21022.8 RTM, with SQL 2005. I've been working on a project that uses Linq, and up until today, everything had been working great. I started to get data cast errors when reading the results from a basic "from .. select" clause. It looked like the error had to do with a mismatch between the column data type in the DB and what was shown in the O/R designer. However, after changing the data types in the designer to match the DB, the problem didn't go away. I decided Read More...
|
-
I'm trying to delete a customer from the database using linq and here's my code Code Block var results = from c in _dataContext.Customers where c.CustomerID == customerName select c; Customer customer = results.First(); _dataContext.Customers.DeleteOnSubmit( this ); _dataContext.SubmitChanges(); when i called DeleteOnSubmit i got this exception System.InvalidOperationException : Cannot remove an entity that has not been attached. so i modified the code and added this line before DeleteOnSubmit but Read More...
|
-
Hello everybody, I've got the following LINQ query: Code Block var q2 = from invD in query group invD by invD.Invoices.Customers.Name into g orderby g.Sum(x => x.NetIncome) descending select new { CustName = g.Key, CustCA = g.Sum(x => x.NetIncome) }; I would like to do something like: Code Block double total = 0; double checkValue = 10000; q2 = q2.TakeWhile(r => (total += r.CustCA) Of course, this one doesn't work. So I tried to replace the assignement by a call to a function: Code Block q2 = q2.TakeWhile(r Read More...
|
-
Hi, I insert customer than order like below Code Block LINQDataContext db = new LINQDataContext (); Customer cus = new Customer () { CustomerName = "Customer4" , CustomerEmail = "Customer1Email" }; Order ord1 = new Order { ProductName = "Pro4" , QTY = 6 }; Order ord2 = new Order { ProductName = "Pro3" , QTY = 2 }; cus.Orders.Add(ord1); cus.Orders.Add(ord2); db.Customers.InsertOnSubmit(cus); db.SubmitChanges(); Now suppose if I have to add 30 orders than I need to create Ord1, Ord2, Ord3...Ord30 than Read More...
|
-
Usually, the SQL table name in LINQ to SQL is statically provided by declaring the TableAttribute on an entity class. In my application, I want the table name to be dynamic: While admins use the normal table, if a non-admin user uses the same class, I want LINQ to use a view instead of a table. The view only contains the records which the user is allowed to see. How do I achieve this? An alternative to a "dynamic" table name would be to automatically insert certain Where predicates whenever a query Read More...
|
-
I apologize in advance if this has been answered elsewhere, but I have been searching the net for HOURS and cannot find anything definitive. I'm trying to bind a LinqDataSource to a stored procedure. I followed ScottGu's excellent samples in his LINQ to SQL series. I have tried all of the following with no success inside the LinqDataSource's Selecting event: 1. Drag the SPROC from server explorer into my .dbml designer and assigned the result of that call to e.Result 2. Created a method inside my Read More...
|
-
Hi All, How should I bind a XML file content to a control, say a grid at runtime using VB.NET/ C# code in WPF version. By Default I binded to a file, but at runtime I need to change the file source. Please suggest. Read More...
|
-
Hi all group, on a web page i m using a listview with linqdatasource and datapager. i have to bind liqdatasource to listview but in the code behind file dynamically. i m using 'selecting' event of linqdatasource to get the final query, like this.. MainLinqDataSource.Selecting += new EventHandler LinqDataSourceSelectEventArgs >(MainLinqDataSource_Selecting); MainListView.DataSource = MainLinqDataSource; MainListView.DataBind(); void MainLinqDataSource_Selecting( object sender, LinqDataSourceSelectEventArgs Read More...
|
-
Hi I am wondering if it is at all possible to test if a specific entity is already attached / known by a data context, besides calling dataContext.Attach(entity) and catch the possible exception that may occure. My problem comes from not knowing if a data context was used to retrieve/insert the entity, or if the entity was retrieved by another data context. Best regards, Egil. Read More...
|
-
Hi, I am using LINQ to SQL in multi-tier architecture (fat client - WCF - app server - db server). The problem is how to create transfer objects (to pass through tiers) with minimum amount of produced handmade code. At the moment in client and server projects I added references to project with DBML file and auto-generated code. Since my auto-generated types don't contain any BL extensions yet in partial methods and wherever (as well as my DataContext) - it is ok to share this project with client Read More...
|
-
I have a User table with two foriegn key constraints to the Address table, "HomeAddressId" and "BillingAddressId" both referencing the ID of the Address table. The User table also contains several other foriegn key constraints to other tables as well. I pulled both of those tables onto the DataContext using the LINQ visual designer in VS 2008. and wrote code to populate a UI with the fields for both the user and his/her associated addresses. The problem I am having is when I reach the code to populate Read More...
|
-
Hi group, I'm beginning with LINQ and I'm having a problem with IEqualityComparer. Here's a dummy scenario: say I have an entity class (let's call it Product) from a SQL database and I want to remove from a IQueryable set all the products in another IQueryable belonging to the same manifacturer. Given that a Product manifacturer is identified by an int member (Product.manifacturerID: a FK in the database), I just want to remove all the products from set a whose manifacturer appears in ANY of the Read More...
|
-
I'm trying to come up with a nice n-tier architecture using LINQ and I've run into a problem. I'm my DAL, I have the DataContext along with the partial entity classes generated by the O/R designer. I then created another partial class with the same name that will actually contain my LINQ queries. Code Block namespace NTierTest.Data { public partial class Product { private NTierDataContext db = null ; public void CreateDataContext() { db = new NTierDataContext (); } public virtual List Product > GetAll() Read More...
|
-
This is my first LINQ Query and while it works I realize that I am probably making the mistakes of a beginner. Please consider the following code and let me have it :) I have 2 questions: 1) Is " where p.EffectiveDate == products.Max(x => x.EffectiveDate)" really only pulling back one of each Category with the highest effective date? 2) If (1) is true then is there a beter way to show the results than to use " select new { ... Name = g.Max(p => p.Name) };" ? The Code: using System; using System.Collections.Generic; Read More...
|
-
Some newbie help on LINQ to SQL Its a really nice feature that if your linq to sql query returns a row previously returned, you end up getting the same entity: but not so clear from the documentation how this really works. For example, given a table MyFoos (primary key "ID") accessed throught DataContext "FooContext": Qry1 = FROM MyFoo1 IN FooContext.MyFoos Select MyFoo1 WHERE MyFoo1.ID = "123" Qry2 = FROM MyFoo2 IN FooContext.MyFoos Select MyFoo2 WHERE MyFoo2.ID = "123" FooElement1 = Qry1.Single Read More...
|
-
I am developing an app in VBE2008 and trying to use LINQ. One problem I ran into is when trying to create a Sum query variable on a dataset, I receive an error message stating: Option Strict On requires all variable declarations to have an ‘As’ clause. What is the proper As clause for Method-Based queries and what is the proper conversion to use with Option Strict On? Generates: Syntax error in cast operator, two arguments seperated by a comma are required.. This example is the "Corrected" code by Read More...
|
-
Hello people: First of all forgiveness for my English. I am working with Linq to SQL, Visual Studio 2008 and SQL Server 2000. When you delete a record and then go back to Insert (ie, insert a record with the same primary key) and I run SubmitChange it generates an key duplicate exception. I am reviewing the SQL commands generated by linq, and I see that attempts to run first insert command, and then delete command. I imagine that this is the problem because I expected the first run delete and then Read More...
|
-
I'm trying to accomplish something that I could write in 10 seconds in sql but can't quite wrap my head around this linq syntax yet. Think of a super simple customer table & order table, I want to return say the top 10 customers based on how many shipped orders they have. here is the sql i would use Code Block select c.* from customer c join orders o on c.customerid = o.orderid where c.active=1 and o.shipped=1 this is the linq i have so far, can't figure out how to filter only the shipped orders Read More...
|
-
I have a Phones table in my database. Then I generated the dbml using the design time tool. Then I added two derived classes on the dbml layout: HomePhone and MobilePhone and regenerated the dbml. Now I need to modify the Phones table structure and regenerate the dbml. As far as I've heard, the only way to do this is to delete the old dbml and rerun the design time tool. But if I do this, I lose the inheritance structure that I had. Is there any way of preserving my manual changes? Read More...
|
-
Code Block [ Table (Name= "dbo.tbl_User" ), Serializable ] public partial class tbl_User : INotifyPropertyChanging , INotifyPropertyChanged is this possible? Read More...
|
-
System Microsoft Windows XP Version 2002 Service Pack2 Intel Celeron Processor 465 Mhz 256 MB Ram Im writing because I've downloaded Adobe Flash Player 9 which downloaded Active x flash9.ocx and it causes Internet Explorer to crash often anybody please help. Thnks to anyone who responds in advance. Have A Happy, prosperous and healthy New Year to Everyone. Read More...
|
-
Hi, let say, I am using Northwind database and that I retrieve one Customer object. I want now to make a query over his/her orders, but I don`t want to use: Code Block var ordersQuery = from o in myCustomer.Orders where o.DateCreated > DateTime.Now.AddMonths(-1) select o; If I use the previous query, all orders are selected from database and filtered in memory. I want the "Where" to be executed in database and only records which pass conditions to be returned. Code Block var ordersQuery = from o Read More...
|
-
Hi all, I am new to Linq technology .We have extensive use of XML in our project. I want to know how beneficial to use Linq with xml rather than using traditional xpath queries. Will there be any performance hit or benefit of this. Regards Gunwnat Read More...
|
-
Hi All! I've been testing out how DLINQ process and throw the queries to SQL Server, one thing I noticed is that when two or more methods are called from a single instance of a Data Class, the preceeding methods tstill do not use the currently opened db connection that was opened by the first method that was called. For ex. DataClass1DataContext test = new DataClass1DataContext(strConn); var testResult = from a in test.GetPeople() select a; test.UpdateName(1, "Enzo"); test.UpdateName(2, "Lorenzo"); Read More...
|
-
Hi All! Is it possible to use DLINQ for stored procedures with multiple resultsets? Thanks, Enzo Read More...
|
-
I am trying to store Linq Entity objects (when using Linq to SQL) in the ASP.NET session when using StateServer. I get an error because EntitySet class is not serializable. One of my entity classes which I am trying to store in session has 1 to n association with another class, hence the EntitySet is being used here. Since objects are first binary-serialized when they get stored in StateServer but the problem is that EntitySets are not binary serializable. I have also tried the option of setting Read More...
|
-
Hi I am using LINQ to SQL. I have a stored procedure which returns a customer details by taking his id as parameter. It will return only one value always. I have dragged and dropped the procedure to designer and VS created method for that. When I call that method, it returns a generic ISingleResult instance, For taking the result from this, do I need to iterate each item using a foreach loop ? Or is there any way that I can directly cast this to Customer class type ? Read More...
|
-
Hello all, I am currently working on an application that will have a datagridview filled with data from a LINQ to SQL query. This query data changes often as I am doing client side paging. Getting data into the textbox, lables, and other user controls was easy enough as I did something similar to the sample below: Code Block dim query = from Projects in CurrentRecords _ skip 3 take 1 me.txtProjectID.text = query.FirstOrDefault.ProjectID What I would like to do is have a line of code like Code Block Read More...
|
-
Hi I want to create my own extensile method that helps me make paging easier. Here is my listing: public static IEnumerable GetPage( this IEnumerable items, int pageIndex) { return items.Skip(5 * (pageIndex - 1)).Take(5); } It works, but not as I expect. I want to effect sql query that is being generated to retrieve only 1 page of data (5 records maximum). But it retrieves all data and then paging is executed. It uses LINQ To Objects instead of LINQ To SQL. How can I correct it? Thanks, radco Read More...
|
-
Hi, I want to build the following scenario, but I am stuck. I have a ASP.NET web site which uses a sql server database instance called " MyApp " via LINQ to SQL. I want to set up another database " MyAppTest " as a test instance which hast the same schema structure as the first one. This second database will be filled with test data. My plan is to be able to switch to the second database when I want to run my test cases. But I can't figure out a practical way to do this. I tried to change the following Read More...
|
-
Please consider this query: var query = from p in dc.Persons group p by p.Address.State; dataGridView1.DataSource = query; The above works ok. It displays one column of all the group keys. Now I want to display all the persons from VA. I could do a filter query, i.e. where p.Address.State = "VA". But I thought I should try starting from the above groupby query and see what happens. So I do a long route: var query = from p in dc.Persons group p by p.Address.State into grps where grps.Key == "VA" select Read More...
|
-
I'm using Visual Studio 2008 RTM. Problem: When i'm drag'n'drop a stored procedure into the dbml designer, it generates a method with a generic ISingleResult type: [Function(Name="dbo.SearchForSomething")] public ISingleResult SearchForSomething([Parameter(DbType="NVarChar(MAX)")] string search) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), search); return ((ISingleResult)(result.ReturnValue)); } I want to use this stored procedure in advanced Read More...
|
-
I have a Patient with two child objects(Address and Phone) using LINQ Association. Scenario 1: Insert Patient with two addresses and one Phone objects. with one insert on Patient will save complete hierarchy. It works fine. Scenario 2: Update Patient records, add new address record to address list, delete one entry of existing address. Update phone object. Say update opration on Patient. Result: It does nothing. No updates/ No insert Can anyone tell me how to do update/insert in one shot for associated Read More...
|
-
Hi all, I'm very new with C# programming and decided to learn this based on the .net 3.5 framework and VS 2008. The error is (as seen before): Error 1 The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?) I installed the full VS 2008 installation (not including the MSDN library). Can't locate the System.Linq.dll file or add the reference in VS. I can only find System.Data.Linq. Can I add Linq manually or via an internet update? Christmas Read More...
|
-
Hi, I have column that is not null and have set default value to 800, suppose colum name is price. Now when I insert record using LINQ db.SubmitChanges(); I get the value in DB as 0. I am not passing column value from LINQ. Here what I pass ProductName = Manago QTY = 12 I insert these values InsertOnSubmit() and not passing Price value which has default value 800. When I check DB I get 0. How I make this work as my default value is inserted when row inserted. Thanks Read More...
|
-
i downloaded a update on december 23rd and it deleted all but 3 of my icons on my computer and i was wondering wtf are u ganna do to stop that from happening agin and how are u gona get my icons back? Read More...
|
-
Hi! A have a table with an identity column (int, autoincrement) in a table. I'm using LINQ to SQL in my project and I have configured the behavior of my Linq to sql table to use a stored procedure for insert because I need to perform a few tests on the whole table before inserting a row. The ID column is autogenerated on insert and I want that after insert the ID property to be set to the newly generated value of the ID. Eventhough I've set "Auto-Sync" , "IsPrimaryKey", "BdAutogenerated" to true, Read More...
|
-
I have my connection string set to a constant in c#. I want my DataClasses.dbml to use that. Is it reasonable to change public DataClassesDataContext() : base ( global ::System.Configuration. ConfigurationManager .ConnectionStrings[ "knovoloDBDevPracticeConnectionString" ].ConnectionString, mappingSource) { OnCreated(); } to public DataClassesDataContext() : base ( global ::System.Configuration. ConfigurationManager .ConnectionStrings[ ProgramConstants .KnovoloWebCS].ConnectionString, mappingSource) Read More...
|
-
Can I create a dbml file for a given view using command prompt with sqlmetal? My basic requirement is I should create a dbml file with a view and later I should be added more views to the existing dbml when ever i require... is there any way to do that? I have tried with c:\>sqlmetal\conn...\views but it is creating dbml with all the views existing in the database given. If any one can help me out ...I will be thankful.... Read More...
|
-
Can I create a dbml file for a given view using command prompt? My basic requirement is I should create a dbml file with a view and later I should be added more views to the existing dbml when ever i require... is there any way to do that? I have tried with option views but it is creating dbml with all the views existing in the database given. If any one can help me out ...I will be thankful.... Read More...
|
-
|
|