|
|
June 2007 - Posts
-
In Beta1, if you add a new entity object to a Table using the Add method, if that entity object contained any associated entity objects, they are automatically added too. But, if you call the Remove method on that new entity object, the associated objects are not removed first, and so the new entity object cannot be removed. This worked in the May 2006 CTP but does not in the beta 1. Here is some sample code demonstrating: Code Snippet Northwind db = new Northwind(@"Data Source=.\SQLEXPRESS;Initial Read More...
|
-
Can LINQ be downloaded separately, or does it require the entire ORCAS download? If it can be downloaded separately, where is the link? TIA Trevor Read More...
|
-
Given the following table schema: Code Snippet Users UserItems Items ------ ---------- ----- Id UserId Id Name ItemId Name SomeField I'm trying to produce a SQL statement like: Code Snippet SELECT Items.Id, Items.Name, UserItems.SomeField FROM Items LEFT OUTER JOIN UserItems ON UserItems.ItemId = Items.Id AND UserItems.UserId = @userId For the life of me I can't get Linq to produce both of the join conditions... It would appear I'd need some flavor of a group join and a DefaultOrEmpty call, but I Read More...
|
-
Hi, I have two tables dropped onto the designer: |Users| |Transactions| ID ID Initials User ID Password The tables have a single relationship: Users.ID (one) to Transactions.[User ID] (many). Initially, I have the Users table populated with users but have no records in the Transactions table. In order to verify a user login to the program, I have written: Code Snippet var currentUser = (from u in db.Users where u.Initials == tbInitials.Text && u.Password == tbPassword.Text select u).First(); Read More...
|
-
Rico has his third installment on LINQ to SQL performance up on his site and he finally lets us in on what he thinks the problems are/were....( read more ) Read More...
|
-
It would be great to have a "classic" IGrouping (ie non-generic), upon which IGrouping<K,T> is based, i.e. public interface IGrouping : IEnumerable { object Key { get; } } public interface IGrouping<K, T> : IEnumerable<T>, IGrouping { K Key { get; } } In the absence of IGrouping classic, does anyone know of a simple and non-grubby solution to this: void Print (object data) { if (data is IGrouping<,>) Console.WriteLine ("Key is: " + ((IGrouping<,>) Read More...
|
-
when i try add a item linq to objects in visual studio 2005 i have error in load the package of the designer somebody can help me thanks Read More...
|
-
I am updateing my dataobjects and then requerying the datacontexts to filter out changed objects i don want Example: var q = from t in ctx.GetTable<Size>() where t.GRADE == "A36" && t.deleted == false select t; foreach(Size s in q) s.deleted = true; //later in another method var q2 = from t2 in ctx.GetTable<Size>() where t2.deleted == false select t2; In the results are the items where GRADE = "A36" in my opinion they should not be shown because of object tracking. Read More...
|
-
I get the following error when I try to do what is described below. 'T' does not contain a definition for 'PrimaryKey' Is this not supported or am I doing something wrong? Code Snippet public class Base ... ... public static T FindBy(int primaryKey) { DataContext context = new DataContext("connection_string"); var entity = context.GetTable().Single(e => e.PrimaryKey == primaryKey); return (T) entity; } And there is also... Code Snippet public class Company : Base<Company> ... ... Read More...
|
-
I have made a dynamic query filter that adds to the where clause in a Linq query: simple example: public interface IDeleted { bool deleted{get;set;} } public class QueryFilter<T> where T:IDeleted { public List<Expression<Func<T, bool>>> Filters = new List<Expression<Func<T, bool>>>(); public DataContext ctx = new DataContext(Constring); public void runFilters() { var query = from t in ctx.GetTable<T>() where t.deleted == false select t; foreach (Expression<Func<T, Read More...
|
-
Hi All, I need a control like DataGrid that you can bind a dataset to it and also support paging in XAML. First of all what control should I use? I realized there is no datagrid anymore. I used List box and it works except there is nothing for paging. What I need is a lister control with customizable row and also databindable which supports paging too. Does anyone have any idea what should I use? Cheers, Sina Read More...
|
-
Could someone please tell me whats wrong with this statement? According to all the examples that I've read this should work but the compiler is balking at the variable o. i thought the o is implied. however the complier is puking on it saying it does not exist in the current context. Im running orcas beta 1. WebstoreDataContext context = new WebstoreDataContext (); Order order = context.Orders.SingleOrDefault(o = o.OrderID == 10); I'd appreciate some insight into this as it is driving me crazy. Read More...
|
-
Here is what i have done. please review and let me know what i am missing: 1. Create an asp.net website. 2. Add reference to System.Core and System.data.linq 3. Add the following code to the code behind of the default.aspx. using System.Data.Linq; string [] cities = { "London" , "Amsterdam" , "San Francisco" , "Las Vegas" , "Boston" , "Raleigh" , "Chicago" , "Charlestown" , "Helsinki" , "Nice" , "Dublin" Read More...
|
-
Using the following code block to select a customer using one datacontext, and save a child object using a different data context doesn't work (ie, the changes don't get propogated back to the database). It's a trivial example, but suppose you saved the "Customer" in a session variable on one page, and wanted to add the order on the next page, would you also need to pass the data context as a session variable also? Attaching the child object manually generates an "Item already exists Read More...
|
-
The LINQ to SQL DBML schema for Beta1 doesn't match the SQLMetal generated DBML file using the /XML option. Since both of these are using .dbml file extensions, shouldn't the files be interchangeable? Shouldn't I be able to take the SQLMetal dbml file and load it into the Designer, and shouldn't I be able to generate source code using SQLMetal from the Designer's dbml file? Are there any plans for this? Will it be in Beta2, RTM, never? Thanks. Read More...
|
-
Hello I have hmm strange problem - my code looks like this document.Save(savePath); XElement documentXml = XElement.Load(savePath); where document is XmlDocument, savePath - some place on HDD, what I want to do now is to avoid saving to disk and stay in memory - is anybody who can help with this ? Read More...
|
-
I'm doing a relatively simple query, using LINQ to SQL agains a SQL Server 2005 Enterprise (locally). When I take the query itself (outputted via .AsQueryable()) and execute it, it completes in about 2 mins. When I run it through the C# program, it seems to take at least 18 hours (I killed it, as I did not let it complete). I used the SQL Server profiler, and saw massive amounts of weird queries constantly hitting the server. Here's the code: Code Snippet var q = from c in table where c.size != null Read More...
|
-
The LINQ book I'm working on is available as an early access edition. You can already buy and download PDFs today. You also have the option to buy the PDFs now and receive the book as soon as it is available. The book covers the full LINQ spectrum. It was written in collaboration with Steve Eichert and Jim Wooley, who you can often find on this forum as well. You can find more information on the LINQ in Action blog . Read More...
|
-
To extend my tracking of Rico Mariani's performance tests to his part 2 , I decided to compare performance of compiled versus conventional LINQ to SQL queries. VB doesn't support lambdas in Beta 1 so I converted my original test harness to C# and added the following code: Code Snippet namespace LINQtoSQLPerfCS { public partial class LINQtoSQLPerf : Form { ... private void btnLINQtoSQL_Click(object sender, EventArgs e) { IEnumerable<Order> Query = null; ... for (intCount = 1; intCount <= Read More...
|
-
Hi, I have some problems choosing correct pattern for working with not owned references. Let say that you have a Person object and this person object has a PrimaryAddress reference. This PrimaryAddress reference is not owned by Person so Address object must not be created and/or updated through Person object, only reference key (PrimaryAddressID) in Person should be changed if necessary. But if you use EntityRef with Association attribute and you create new Person object and than you set PrimaryAddrress Read More...
|
-
Rico continues his series on LINQ to SQL performance. In this post he takes a look at the breakdown of where the time is being spent. It's not looking good for the extra overhead of query translation. Rico ponders a solution....( read more ) Read More...
|
-
Hello I´m trying to generate one dll in memory. To do this I use CodeDom to generate a new Class. Then I compile this class with a compiler to generate the dll. This file is stored on disc to save it in the database and delete from disc. I want to do this but the generated dll must store on memory. Then I want to copy this dll to database and delete from memory. It´s possible do this? Here is the compiler that generate dll on disc.I use orcas: public class Compiler { public static byte [] Compile( Read More...
|
-
I am tyring to establish a best practice for my new version of the applicaiton but ı could not make up my mind if I should use dynamic query feature in LinQ to SQL or I should write many get funtions that turn the same type objects but with different predicates. any guidelines? Read More...
|
-
Rico Mariani, our performance expert amongst other things, has a blog post detailing worst case peformance shown by LINQ to SQL in last May's CTP. You can see for yourself that performance really sucked. :-) Fortunately, that was the prototype and lots...( read more ) Read More...
|
-
if (( this ._Service.Entity != null )) { this ._Service.Entity = null ; this ._Service.Entity.JobbersOfferingThisService.Remove( this ); } Why is it try to call members of Entity after setting it null. I was wondering why i am unable to delete a row, and after debugging it led me to the above autogenerated code by dlinq. Read More...
|
-
I get this error whenever i update a row's boolean field to false (bit field). System.NotSupportedException: SQL Server does not handle comparison of NText, Text, Xml, or Image data types at System.Data.DLinq.ProviderBase.ValidateNoInvalidComparison.VisitBinaryOperator(SqlBinary bo) at System.Data.DLinq.ProviderBase.SqlVisitor.Visit(SqlNode node) at System.Data.DLinq.ProviderBase.SqlVisitor.VisitExpression(SqlExpression exp) at System.Data.DLinq.ProviderBase.ValidateNoInvalidComparison.VisitBinaryOperator(SqlBinary Read More...
|
-
I've been trying to use the Aggregate operator to reduce the size of the following code block: MultiBinding mb = new MultiBinding (); mb.Bindings.Add ( new Binding ( "Name" )); mb.Bindings.Add ( new Binding ( "IsReadOnly" )); mb.Bindings.Add ( new Binding ( "IsDirty" )); mb.Bindings.Add ( new Binding ( "IsRecovered" )); (( Binding ) mb.Bindings [ 0 ]) .Source = model ; (( Binding ) mb.Bindings [ 1 ]) .Source = model ; (( Binding ) mb.Bindings [ 2 ]) .Source Read More...
|
-
Anyone have a C# example showing how to use XStreamingElement? I'm just trying to parse very large (yet simple) XML files. Thank you. Read More...
|
-
Is there a way I can create enums from a look up table in a database?? For example: If I have a table: Status, with statusID and statusDescription and I want to have some object in C#: public class SomeObject { Status status; ...... } enum Status {...} Is there a way I can do that using LINQ , to have all the statuses in compiling time ??? Read More...
|
-
just curious how this'll be handled. having queries directly embedded in the code is awesome from a type safety standpoint, but what about at runtime? i assume some kind of "on-demand" Compiling for a program like "SQL Query Analyzer" (more aptly named LINQ Query Analyzer) that is dynamically compiling these LINQ queries and seeing results, kinda like snippet compiler. I bring this up becomes sometimes you gotta give query ability to the users (report generation etc) Read More...
|
-
Is there any way to update or delete without performing the select first? for now I don´t think so, but in the future? Read More...
|
-
Hi, I've got a piece of code that is giving me a runtime exception that may be a bug in Linq to Sql (either that, or I've done something dumb that looked OK to the compiler!) The code is pasted below, but basically it revolves around constructing objects in the select clause that derive from an interface, and then using the results of the Linq query to populate a List<> object: namespace LinqProblem { class Program { static void Main( string [] args) { using ( DataClasses1DataContext context Read More...
|
-
Hi, How easy will it be to get Mock query objects using LINQ? i.e. it might be nice to intercept calls to prevent LINQ to SQL from incurring the cost of DB calls during a unit test. Andrew Matthews Read More...
|
-
I'm using C#, Linq, .Net Framework 3.5 on Windows Server 2003 w/ 4GB of RAM. I am running a query against an XML file (nearly 2GB in size). Very early on during execution, I get the output: Unhandled Exception: OutOfMemoryException. I'm not sure if its possible to optimize my code for this (very simple, few line app, that does nothing else): Code Snippet XDocument xmldoc2 = XDocument .Load( @"List.xml" ); var q4 = from table in xmldoc2.Descendants( "Table" ) where table.Element( Read More...
|
-
Recommended reading: Matt Warren has posted an eloquent essay, LINQ to SQL: Objects all the way down , on the objectives of LINQ to SQL and the extent to which they've been achieved in v1. Anyone with more than a casual interest in LINQ and O/RM with LINQ to SQL should read it in full. My favorite feature of LINQ to SQL: It's shipping in VS 2008! --rj P.S.: If you haven't read it already, you also might enjoy Matt's The Origin of LINQ to SQL post, which provides a bit more perspective on the last Read More...
|
-
There are a lot of different opinions on just what LINQ to SQL is or is not. Some of them are actually based on investigation by people who have kicked the tires and taken a test drive. Being its architect, I realize that I am the foremost expert on what’s under the hood, yet that alone does not give me the omniscience to know how the product measures up to everyone’s expectations. What it does give me is the ability to share with you the impetus behind the design and hope that gives you enough insight Read More...
|
-
Is there no type safety when building expression trees or is it me? Code Snippet class Program { static void Main( string [] args) { var foo = new Foo (); var bar = new Bar (); var c = Expression .Constant(foo, typeof ( Foo )); var b = Expression .Constant(bar, typeof ( Bar )); var a = Expression .Add(c, b); //Accepted by the compiler var p = new ParameterExpression [0]; var e = Expression .Lambda< Func < int >>(a, p ); var f = e.Compile(); //accepted by the runtime compiler var ouch Read More...
|
-
hi guys how can one do a left join. ex: all customers + shipping address for the ones that have shipping address, given that customer and shippingadress are two tables. Read More...
|
-
Hi All, I'm trying to implement a solution to GroupJoin on my LinqToRdf query provider. I'm finding it REALLY hard to work out where to start. I'm still using the May 06 CTP of LINQ. Here's what I'm trying to get to work: TestContext db = new TestContext (CreateSparqlTripleStore()); var q = from a in db.Album join t in db.Track on a.Name equals t.AlbumName into tracks from tr in tracks where tr.GenreName.Contains( "History" ) select new Album {Name = a.Name, Tracks = tracks}; The Expression Read More...
|
-
I have a question that is related to LINQ and C#: Is that a way to save a query expression into a type "expression" so that I can pass that to LINQtoXML, LINQtoSQL, LINQtoObject. What I am saying is that I want to save my expression and depending on the setting, I could pass the expression to either XML, SQL, or Object ? Thanks Read More...
|
-
Code Snippet var q = from table in xmldoc.Descendants("Table") group table by table.Element("name") into g where g.Count() > 0 select new { Name = g.Key, Count = g.Count() }; foreach (var name in q) Console.WriteLine("Name = {0}", name); Always returns: Code Snippet Table Name = { Name = <name>John</name>, Count = 1 } Table Name = { Name = <name>George</name>, Count = 1 } Table Name = { Name = <name>Sam</name>, Count = 1 } Table Read More...
|
-
so here is the situation: in between table order and table products and a intermediary table named orderdetail whose primary key is a compound key consisting of orderid and productid. in linq i can do AOrder.orderdetails but is it possible to get all the product entities that are part of that order. I was hoping something like : AOrder.orderdetails.products. Is this possible? Read More...
|
-
I am expiramenting with DLINQ and trying to encapsulate database actions within a single class. As part of this, I have a base class that contains standard fields that will be in every record, in every table (such as primary key, version, etc.), and it also contains the event for notifying DLINQ of changes. When I set this up (code sample below) and try to insert a new record, I get a NullReferenceException thrown (see below). However, if I remove the base class and put its properties in the main Read More...
|
-
Hello. I have been experimenting with Linq to SQL and have a number of questions: Consider the following code block (user class represents a user of the application): /// Use this to retrieve the user instance when first logged on. public User GetLoggedOnUser(int loggedOnUserId) { MyDataContext dc = new MyDataContext(); User result = dc.Users.Single(u => u.UserId == loggedOnUserId); return result; } ///Elsewhere in the life of the application ///Do something with the user, and save the changes. Read More...
|
-
Well I was playing around with Linq a bit today, and found - what I think is - a performance bug. I was doing some very ugly (yes I know) performance test of using Linq vs. the old fashioned way of looping through some collections. Here is the code: List <Customer> customersFromDatabase = GetCustomersFromDatabase(); List <Customer> resultList = new List <Customer>(); Console .WriteLine( "Start old fashioned way" ); DateTime start1 = DateTime .Now; for ( int i = 0; i < Read More...
|
-
I have a simple piece of C#/LINQ code that targets an XML file. Unfortunately it does a SQL against an element that is not always in each record in the XML file. What I need it to do, is still process the rest of the XML file, rather then just throw an exception and die. XDocument xmldoc = XDocument .Load( @"list.xml" ); var q = from table in xmldoc.Descendants( "Table" ) where ( int ) table.Element( "size" ) > 0 select ( string )table.Element( "name" ); Read More...
|
-
I've installed Orcas beta1 (9.020404.0) March CTP on Vista Ultimate and there aren't any LINQ related DLLs. I see System.Data.Linq.xml and System.XML.Linq.xml in the .NET 3.5 folder but no DLLs. I've searched my machine and can't find anything related to LINQ. Does Orcas require another seperate download to use LINQ? Or is there some place to download the above related DLLs? Thanks, Brett Read More...
|
-
Hi i am trying to figure out how to write the following query in LINQ Select * from employee where emp_id not in (Select emp_id from tester) Read More...
|
-
I seem to have got into an odd situation here. I create a new Invoice object and set the Customer property to a valid customer. The user then "Cancels" out of the form so I never dc.Invoices.Add(myInvoice) and expect it to go away. The next time dc.SubmitChanges() happens in another part of the program it will attempt to persist this new Invoice - presumably because of the Customer relationship (if I dig into the ChangeTracker I see the Customer in there). I can't set the Customer property Read More...
|
-
Binding a variable to an Expression Tree seems trivial when generating a Expression Tree but what if I want to bind a free variable to an Expression Tree inside a method? Code Snippet public void BindingFV() { Foo foo = new Foo(); foo.id = 5; Expression<Func<Foo>> e = () => foo; foo.id = 4; var v1 = e.compile()().id; // v1 = 4 } Is there an equivalant way to write this by building the expression tree your self? If the binding had been to a class variable Expression.MakeMemberAccess Read More...
|
-
Hi, is there (or will there be) an way to store the result of an Linq query to a public or member variable or return-value? regards, -christoph Read More...
|
-
What is is the best practice when we want to use "dynamic sql" in terms of using LinQ? such as the user interface indicates the predicate condition. SELECT * FROM PERSON WHERE (1) NAME LIKE @NAME AND (2) GENDER LIKE @GENDER is it possible to have a query that encapsulates all combinations.? 1.there is no where condition 2.only name is asked 3.only gender is asked 4.both gender and name asked var persons= from prs in db.PERSONs if( (@NAME =!null)***** where prs.NAME.contains(@NAME) if( (@GENDER Read More...
|
-
After starting the install package "LINQ Preview (May 2006).msi" a message box appear: There is a problem with this Windows Installer package. A script required for this install to compleate could not be run. Contakt your support personel or package vendor OS: WinXP Home SP2 (all purposed updates installed) What can I do ? Ps: IE 7 Beta 2 is installed Read More...
|
-
Hi all, I am new to LINQ and exploring LINQ using VS Orcas with C# 3.0 and .NET framework 3.5. I used "Linq to SQL file" template to create a mapping. Then in my sample form app, I added the following var local = from c in Customer where c.CustomerID > 0 select new { id = CustomerID }; it complains that customer does NOT contain a definition for 'where'. 1) Am I missing any #using namespace ? 2) Am I doing it right by using mapping template ? BTW, I can see that the template already Read More...
|
-
How I can initialize generic dictionary in beta1? Code Snippet new Dictionary<>{{"a","b"}}; dosen't work and it seems not documented anywhere. Thanks. Read More...
|
-
Hi MSFT development team I found a article about "Changes Coming to LINQ for SQL ". http://oakleafblog.blogspot.com/2007/05/changes-coming-to-linq-for-sql.html In this article they talk about a "mini-connectionless DataContext" which would be absolutely necessary to implement a multi-tier application over a WCF service interface. I understand "connectionless" does not need a direct database connection and uses WCF, Remoting, Webservices, etc. instead. Now my questions Read More...
|
-
-
Is there a specific reason expression trees uses R-value for closure unlike anonymous delegates use of L-value? Code Snippet static void Main( string [] args) { int i = 1; Func < int , int > f = j => i + j; Expression < Func < int , int >> e = k => i + k; i = 2; var v1 = f(40); // v1 = 42 var v2 = e.Compile()(40); //v2 = 41 } //Jens Read More...
|
-
Using the Northwind as an example, say I want to create a method called GetProducts() Takes in a GetProductsRequest object contains variables the mirror the fields in the products table. And returns a GetProductsResponse object which contains records for the product as well as matching records from the Category table. As you can see in the NW database the CategoryId field has the FK relationship. The UI allows the user to specify a value for any of the fields in the product table as a part of their Read More...
|
-
When I tried to query the xml, this error occurred: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?) I have included System.Xml.Linq reference. What's wrong here? Code Snippet XDocument loaded = XDocument.Load(@"C:\contacts.xml"); // Query the data and write out a subset Read More...
| |
|