|
|
September 2007 - Posts
-
How to create a table and a field in a SQL Database using linq to SQL. Read More...
|
-
Hi all, I have kind of methodology related question... Let's say there are two developers working on the same project where DAL is created using SqlMetal. There is some file AdventureWorks.cs in the SSafe and each of them checked-out it locally. Now, 1st developer works on the SP A(), while second works on the SP B(). When each of them would commit their changes in DB and regenerate AdventureWorks.cs to use updated SP - they both would get each-others changes. This is not always desirable. What's Read More...
|
-
Hi all, I'm trying to add tables from AdventureWorks installed on my local computer to a .dlinq designer in a sample application. It works for AdventureWorks tables that are not related to a schema (like ErrorLog or DatabaseLog), but doesn't works for none of the tables related to any scehma (HumanResources, Production, ...). When I trying to add a table related to a schema (by dragging it to design surface) - VS 2005 frozens for few seconds and then just nothing happens. There is no error message, Read More...
|
-
I’ve run into an issue with LINQ to SQL that looks kinda scary . I’m using some code that detaches and re-attaches entities. I found that this works fairly well with single entity instances. The following works fine and dandy (assuming I have a timestamp field on the table): TimeTrakkerContext context = new TimeTrakkerContext (); EntryEntity entity = context.EntryEntities.Single(en => en.Pk == 110); context = null ; entity.TimeOut = DateTime .Now; context = new TimeTrakkerContext (); context.EntryEntities.Attach(entity, Read More...
|
-
Hi,new to linq and therefore struggling a bit. We are in process of writing a new Dal at work and wondering whether we can eliminate some stored procedures. What concerns me the most is that when using Stored Procedure you can put as many select -updates and so on and it's only 01 call to the database the sp does the rest. With Linq to sql not using SPs i wonder whether i will incur in many network trips unnecessarily!!!. EG All our SPS check some permission first by calling another SP and then if Read More...
|
-
Hi, In my database design I've several teachers who can teach different classes. My database design (in short and no sql syntax): table Teachers(int teacher_id, string firstName, string lastName) table Classes(int class_id, string className) table ClassDivision(int teacher_id, int class_id) Now I want an output as follows: Teacher A: Classes 1, 2 and 3 Teacher B: Classes 1 Teacher C: Classes 4 and 5 How can I query and output this through LINQ? thanks kGenius Read More...
|
-
Hi all, I have a problem that I am not able to solve for weeks: wehen I try to add a new entity to the datase that is connected to an existing object in db via a relationship, then I get the error "Cannot add an entity with a key that is already in use." I believe LINQ generates another INSERT though a company with the primary key already exists. How can I tell LINQ just to insert the Employer but not the Company? Here is a short description of what I am trying to do: Code Block [Table(Name="dbo.Company")] Read More...
|
-
Trying to figure this out with no luck yet. Table (datetime columns assume all same day): Seq InTime OutTime 1 12:00pm 3:00pm 2 1:00pm 4:00pm 3 11:am 1:00pm 4 5:00pm 6:00pm I need some kind of self-join or correlated sub-query to do this that should return records 1,2,3 as they overlap each other. TIA Read More...
|
-
How can I use LINQ to auto increment a primary key. Using the "AutoIncrement" property of the data column by setting it to true I can not manage to make use of the db's auto increment feature when inserting entries created using LINQ without explicitly adding the id (primary key value) by hand. Using the following code to create a new db entry using LINQ Code Block NewEntity newEntity = new NewEntity (); newEntity .Value1= "First value" ; newEntity .Value2= "Second value" ; //newEntity.Id stays unset Read More...
|
-
I am new to Linq and therefore I might be missing the obvious. I have used sqlMetal to generate storedProcedure for the Northwind Database as follows SqlMetal /Server:MyServer /database:Northwind /pluralize /sprocs /namespace:Northwind.Data /code:NorthwindDal.cs/ When look at the output i see the following Code Block [Function(Name= "dbo.GetCustomersInCity" )] public ISingleResult GetCustomersInCityResult > GetCustomersInCity([Parameter(Name= "City" , DbType = "NVarChar(30)" )] string city) { IExecuteResult Read More...
|
-
-
Hi, I'm 5 months through a traditional n-tier, 17 month, development project. It is currently developed in .NET Framework 2 and uses controls from Infragistics and Component One. I use Visual Studio 2005 and SQL Server 2000/2005. Over the past day or so i've been looking at Linq using Visual Studio 2008 Beta 2 and have been really impressed with the power and ease of it. I currently have a traditional data access layer which talks to SQL stored procedures. I have reams of classes which mirror the Read More...
|
-
What is recommaned way of handling droped connection in LINQ? The only option i see now is wrap code in try/catch everywhere i use LINQ entities. This doesn't seem like a right way. Any suggestions? Read More...
|
-
Hi all, for a project I have, my team decided to try working with Entity Framework and use LINQ to query the entities. To make my question more visible, I've also embedded a simplified code of our project which you can see below. We're using 3-Layer architecure (Presentation, Business, Data). The Main class below represented the Presentation Layer, and both getParticipant(...) and saveParticipant(...) methods are to be placed in the data layer. What I want to do here is : 1. Create a participant Read More...
|
-
Hi All, Please consider the following database model Boy (table name) pk_BoyId (field) Name (field) BoyGirl (table name) fk_BoyId (field) fk_GirlId (field) Girl (table name) pk_Girl (field) Name (field) When using the ADO.NET Entity Framework model wizard on this database model the result is 2 entities Boy (Entity) pk_BoyId (Member) Name (Member) Girl (navigation property) Girl (Entity) pk_GirlId (Member) Name (Member) Boy (navigation property) Now How can I create a collection of girls to use in Read More...
|
-
From what I've read, the way you are supposed to validate an entity in LINQ to SQL before you save it is to implement the OnValidate() partial method on the entity object and then throw an exception if something isn't valid. I would prefer to validate everything that is going to be saved, collect all of the validation errors, and then throw an exception that contains the list of validation errors. This way, I can accurately return to the user a list of things that went wrong rather than just one Read More...
|
-
Hi All, I am getting a weird error when i try to join with this code: WIETD.Business.Objects.SearchParameters searchParams = new WIETD.Business.Objects.SearchParameters(); WIETD.Business.Objects.SpecificationOption specOp = new WIETD.Business.Objects.SpecificationOption(); specOp.SpecOp_Id = 1; searchParams.specificationOptions.Add(specOp); using (WIETD.Business.Objects.WIETDentities context = new WIETD.Business.Objects.WIETDentities()) { var touristEvents = ( from TE in context.TouristEvent from Read More...
|
-
I am just thinking out aloud here to verify how I believe LINQ implements change tracking. When LINQ materialises an entity it sets the new entity’s Property Changing EventHandler to an internal DataContext change tracking handler. When the first property in an entity object is changed LINQ identifies the situation via the Changing Event and clones a copy of the entity’s initial state into a private internal collection for change tracking purposes. When SubmitChanges() is invoked on the DataContext Read More...
|
-
Hello All, Is it possible to use execute a SP in LINQ and have it return an instance of a class defined in another assembly? -- Regards, Travis Spencer Read More...
|
-
Hi All, Please consider the following database model Boy pk_BoyId Name BoyGirl fk_BoyId fk_GirlId Girl pk_Girl Name When using the ADO.NET Entity Framework model wizard on this database model the result is 2 entities Boy pk_BoyId Name Girl (navigation property) Girl pk_GirlId Name Boy (nabigation property) WHat ever i try I cant list the boys and all the girls they are related to using this code Code Block var boys = from b in context.Boy from g in b.Girl select b; foreach ( Boy boy in boys) { Console Read More...
|
-
I'm just thinking about Expression serializable in C#3.0, if it is we can pass the expression through web service and apply on distribution system. So anyone could give me an answer or any one did that kind test? Paul Read More...
|
-
hi, using Orcas Beta 2, i have created a DataContext class for a compact framework 3.5 application, based on a simple database. the DataContext class compiles fine in a Windows Console App Project, but it doesn't compile in the Compact Framework Project. Here is the SqlMetal command i'm using. "C:\Program Files\Microsoft SDKs\Windows\V6.0A\Bin\SqlMetal.exe" /Provider:SqlCompact "C:\Users\Tim\Documents\VS\App\Db.sdf" /pluralize /code:"C:\Users\Tim\Documents\VS\App\DataContext.cs" /namespace:"Whatever" Read More...
|
-
Hi, I have VS 2005, XP machine. What do I need to start working with LINQ? Thanks Jeff Read More...
|
-
hi guys, just downloaded the beta 2 of VS. really like the idea of LINQ but am very new to it so my apolagyies if this is a stupid question. i have a solution with different projects, i would like to share the LINQ table classes amoung these projects so i'm wondering if these auto-generated LINQ table classes are serializable? if so are there any issues i should be aware or cautous of? many thanks b. Read More...
|
-
Hi I am reading the LINQ COOKBOOK recipes1 article( http://blogs.msdn.com/vbteam/archive/2007/06/22/linq-cookbook-recipe-1-change-the-font-for-all-labels-on-a-windows-form.aspx ) and want to rewrite the code in C#. As I know nothing about VB.NET and also new to C#, I got errors very quickly. Here is the original VB.NET code: Private Sub Button1_Click( ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each label In GetLabels( Me ) label.Font = New Font( "Comic Sans Read More...
|
-
This is a post V1.0 release request. I appreciate that the designers of LINQ to SQL have avoided an entity persistence base class since that would be counter to Persistence Ignorance principals. However I keep find situations in my application where I would like some of my entity classes to derive from my own common EntityBase class. It would be great if the LINQ to SQL entity generator could be directed to use an application base class whenever it finds a DB table containing a one-to-one match with Read More...
|
-
Immediately after re-installing Orcas VWD Express Beta 2, I attempted to add a Linq to SQL item to my current web project. The item is added to app_code, then the following error is displayed in the error list: "The custom tool 'MSLinqToSQLGenerator' failed. Could not retrieve the current project." I am unable to open/modify the Linq to SQL item, and I've run out of ideas after uninstalling/reinstalling everything. Anyone? Read More...
|
-
I was browsing the "101 LINQ Samples" at http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx and I came across a few samples that I can't get to work in Visual Studio 2008 (Beta 2). It's about the SelectMany samples. The code on the webpage performs join operations using a comma, e.g.: Code Snippet public void Linq15() { List customers = GetCustomerList(); var orders = from c in customers, o in c.Orders where o.Total select new {c.CustomerID, o.OrderID, o.Total}; ObjectDumper.Write(orders); } Read More...
|
-
I am executing a query using DataContext.ExecuteQuery. This is complex query. This will return data from 2-3 tables. Context.ExecuteQuery DataTable >(Query, Parameters); It gives me an error for some read only property initialization. I realised, I can give only custom class name instead of DataTable and it works fine. Is there any way get results directly in DataTable/Dataset? Hasmukh Read More...
|
-
Hi, New to Linq to Sql and I have been using SqlMetal to explore it's capabilities on a real world DB. I have noticed that It works without a hitch on Northwind ,however I tried on real world DB and got errors after errors in trying to extract SPS. The error I got is Warning SQM1014 Unable extract Stored Procedure "GetAllCustomers".Invalid object #Countries. It seems that it cannot handle SPS with temporary table or nested SPS. Is this the case? Is there a list of limitation that SqlMetal for obvious Read More...
|
-
When LINQ to SQL generates my business entities, I notice that there are partial methods for OnCreated() and OnLoaded(), but there's no "OnSaved" method. I need to know anytime that an object is about to be saved so that I can update some stuff before I save. Is there any way to find this out? Thanks Jon Read More...
|
-
I am considering injecting some validation routines into the entity class property setters AOP-style (Aspect Oriented Programming). Would such an architectural decision trip up the internal entity initialization within LINQ? Put another way does LINQ populate entity classes via the public property setters or the private column fields? My current AOP tool of choice would be PostSharp. Read More...
|
-
I am creating an app with all LINQ objects inheriting from a base class. I want to provide a static method that will allow me to retrieve an object based on the primary key. I can't however seem to get the LINQ query to work. Below is the code for the method I have been working on. public static T GetById( int id) where T : BusinessBase { Type objectType = typeof (T); Type columnType = typeof ( ColumnAttribute ); PropertyInfo pkProperty = objectType.GetProperties().Where ( prop => prop.GetCustomAttributes( Read More...
|
-
Hi I have Microsoft Visual Studio 2005 Team Suite SP 1 installed on my machine and SQL Server 2005. I downloaded the LINQ May CTP from http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&displaylang=en Installation was fine and I was able to run the samples. But interestingly I couldn't create a new LINQ project as there are NO Linq templates visible in the installed project templates. Am I missing anything here. Thanks in advance, Prudhvi Read More...
|
-
Entity classes generated by SqlMetal are "partial", this assumes that I can add my own logic, for example add some properties, that calculate data from database records (Column attribute marked properties). [ Table (Name= "Tests" )] public partial class Test : System.Data.Linq. INotifyPropertyChanging , System.ComponentModel. INotifyPropertyChanged { //SqlMetal generated code } //My own code public partial class Test { public int SomeProperty { get { return [Something calculated from existing props Read More...
|
-
Since deleting an item of an EntitySet will only remove it's association (by setting the primary key to null), I need to delete items from it's base Table to actually delete them. But how do I generically determine the base table from an EntitySetBindingList? Read More...
|
-
I am testing out LINQ with C# 2008 Express. I have a DB file connection. When I update an object I can trace all the way through to the dynamic code and I call the " SubmitChanges I" method. I do not get any errors. The objects are added to the collection without issue. When I look into the DB the data that I think I have just inserted is not there. Obviously if I re-run the application any data I added is lost (so are the updates). I am at a loss. It is all working so wonderfully except for the Read More...
|
-
I've read through the forums and come to realize that the ability to add custom attributes to entities and properites is no longer supported via the designer as of Beta 2. However, I haven't yet seen how it can be accomplished. I know that I can create a partial class file and apply an attribute to the class, but how is this expected to be handled for the properties? Several people asking about this feature used WCF and the Validation block as examples of common use of attributes. Since I haven't Read More...
|
-
Hi I'm trying to implement 'LINQ to WCF' as case study. My idea is to use a serializable equivalent for each existing expression. This means 'SerializableMethodCallExpression', 'SerializableUnaryExpression', etc. These Expressions looks like that (just as example): Code Snippet [ Serializable ] [ DataContract ] public abstract class SerializableExpression { public SerializableBLOCKED EXPRESSION { } public SerializableExpression( Expression BLOCKED EXPRESSION : this ( expression.NodeType, expression.Type Read More...
|
-
I want to represent data in the form of classes instead of datasets and then i want to add methods to the classes. In the past i did not have any O/R tool available to me. Now with LINQ i hope i can get what i am looking for. What i want is to use a tool like LINQ so that i dont have to create the O/R mapping myself. I then want to extend the functionality of the classes using partial classes so that they have methods too. Then i want to bind my datagridviews to a collection which i am not sure what Read More...
|
-
Dear NG, I'm using AdventureWorks-Database in my example. I'm trying to execute the following Query Expression var qry = ( from cr in _db.Currencies select cr).SkipWhile(cr => cr.Name.Length >= 10); After execution, I'm always getting the error "The query operator 'SkipWhile' is not supported." What is wrong here? Best, Ozgur Aytekin Read More...
|
-
I am trying to implement a custom implementation of the order by operator that takes collation into account. But I am stuck at already the first step. Code Snippet public static IOrderedQueryable OrderByWithLocale(this IQueryable source, Expression> keySelector) { if (source == null) { throw new ArgumentNullException("source"); } if (keySelector == null) { throw new ArgumentNullException("keySelector"); } MethodInfo x = (MethodInfo)MethodBase.GetCurrentMethod(); Type[] y = new Type[] { typeof(TSource), Read More...
|
-
Orcas comes with a nice feature for DataSet where you can generate TableAdapter in another project as DataSet. It would be perfect if LinqToSql could do the same. Database context could be placed in Persistence project and enitites could be placed in DataObjects project and used on server and client side of n-tier applications. Or is it already possible to separate databasecontext and entities? Read More...
|
-
Hi! See this code: customer = new Customer(); customer.Name = "Danilo"; WeakReference wk = new WeakReference(customer); customer = null; GC.Collect(); Running this code, after the Collect, the customer instance is correctly collected by GC. customer is a global static field. But, take a look at this: DbCustomerDataContext context = new DbCustomerDataContext(); customer = new Customer(); customer.Name = "Danilo"; context.Customers.Add(customer); context.SubmitChanges(); WeakReference wk = new WeakReference(customer); Read More...
|
-
While testing my knowledge of how the DataContext entity cache works I saw an unexpected 2nd sql select traced in the SQL Server Profiler as my code queried for the same entity a second time within a DataContext. The data context correctly identifies when it has just re-selected a cached entity because it does not overwrite an uncomitted field change made after the first select. Code Snippet MyDataContext db = new MyDataContext(); int primarykey = 1; var x = db.Customers.Single( o => o.Id == primarykey Read More...
|
-
Hi all , I am talking about the 'Linq To Sql' generated DBML file, in the Orcas Beta1, we can add our custom define attribute into DataContext, DataClass, MemberProperty(DataClass is named 'Table' and MemberProperty is named 'Column' in Orcas Beta2), just something like : but i feel very sorry , in Beta2, i could not find the way to do this again, http://schemas.microsoft.com/linqtosql/dbml/2007 "> '>http://schemas.microsoft.com/linqtosql/dbml/2007">http://schemas.microsoft.com/linqtosql/dbml/2007 Read More...
|
-
In other words, can we use the dynamic query sample in commercial programs? Thanks Joe Read More...
|
-
Hi My problem is that I need to join a table to two others. Table layout is like this PersonPropTable PersonID PropID PersonTable PersonID PropTable PropID In Linq if I get a list of properties from the prob table how can I find out which person is linked to that property? I've tried a nu,ber of joins but they never return results. var q = from p in i.Person join m in i.PersonProp on p.PersonID equals m.PersonID join pr in i.Prop on m.PropertyID equals pr.PropertyID select new { AskingPrice = pr.AskingPrice Read More...
|
-
This question highlights my lack of knowledge in writing a generic method. All tables in my database have an integer primary key called “Id”. So I tried to enhance my DataContext class with a generic method to fetch a single row by the primary key. This is what I coded but the c# compiler objected, I am close to a solution? public partial class MyDataContext : System.Data.Linq.DataContext { public T FetchSingle( int primaryKey ) { return this.GetTable().Single( o => o.Id == primaryKey ); } Desired Read More...
|
-
Hi, i am doing a module for some functionality but i have a problem, i want to make my Linq to Sql Autogeneratod-Entities visible for the user of my module, buy i don't want him to access some of the Entity properties, for security, i am the only one that modifies those items. Example: [Table(Name="dbo.Something")] public partial class Something: INotifyPropertyChanging, INotifyPropertyChanged { .... private EntityRef _SomeEntity; .... [Association(Name="....", Storage="_SomeEntity", ThisKey="...", Read More...
|
-
Dinesh is keeping us up-to-date with LINQ to SQL changes from beta 2 to RTM. In this post of his: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2170562&SiteID=1&mode=1 he mentions there was a change made in LINQ to XML. Is anyone on the LINQ to XML team going to let us know of changes post beta 2? It would be very helpful if someone could. Thanks. Read More...
|
-
I am getting an install error....very frustrating. ..... Below is the log file. pls help === Verbose logging started: 9/21/2007 11:25:08 Build type: SHIP UNICODE 3.01.4000.4039 Calling process: C:\WINDOWS\system32\msiexec.exe === MSI (c) (28:1C) [11:25:08:204]: Resetting cached policy values MSI (c) (28:1C) [11:25:08:204]: Machine policy value 'Debug' is 0 MSI (c) (28:1C) [11:25:08:204]: ******* RunEngine: ******* Product: LINQ Preview (May 2006)(2).msi ******* Action: ******* CommandLine: ********** Read More...
|
-
When I have a Parent->Child1->Child2 relationship and I call ToBindingList() on Child1, are the Child2 entities also converted to static data? For example, Customer->Order->OrderDetail I want to convert all the orders for a customer into a BindingList. Each Order has multiple OrderDetail entries. Do I need a separate call to make the OrderDetail Tables static? Brian Read More...
|
-
Another late-in-the-cycle change in LINQ to SQL that will be visible in RTM: In beta2, the default .NET type for mapping an XML column was LINQ to SQL's XDocument. In RTM, the default will be XElement. Reason: due to a late change in LINQ to SQL, XDocument cannot be serialized with the DataContract serializer. XElement can still be serialized. We wanted to make sure that if you choose the serialization option in SqlMetal or designer, the resulting classes are indeed serializable. Hence, we have changed Read More...
|
-
hi, i'm building up a query using System.Linq.Dynamic and i have the Where and OrderBy parts working nicely. however i'm stuck on the dynamic group by, i can't figure out the syntax despite the quite helpful docs bundled with the samples. below is the query that does work, although as you can see the GroupBy and Select are still using the declarative non-dynamic approach: var result = db.Audits. Where("Auditor <> NULL"). GroupBy(z => z.Cycle). Select(z => new { Cycle = z.Key, Total = z.Count() }). Read More...
|
-
My understanding is that LINQ to SQL ignores default Constraint generated values defined in the SQL Server schema and also LINQ to SQL does not allow a developer to set a LastModified datetime column to the DB server time via GetDate(). In the past year anther ORM vendor dealt with the above limitations after a customer claimed these would cause a system to fail compliance regs when financial audit information was generated. The view is that desktop PC and web farm server clocks were not considered Read More...
|
-
I have a SQL table with an Xml column and am having trouble querying it in LINQ. I'm trying to check if the Xml contains a specific element off the root (I'm doing a bit more, but it boils down to this): (from p in db.Packets where (p.PacketXml.Root.Element("TouchCount") != null) select p ) PacketXml looks something like this, and the TouchCount element is not necessarily always there on every record: The LINQ statement compiles, but when I run it I get this: System.InvalidOperationException: Member Read More...
|
-
I have a SProc that returns a column of bit type. I call it using ms application blocks to bind a GridView. Results are True or False. All good. Using the same SProc, but this time calling it from LINQ, all the results are False, when some of them are supposed to be True. Any ideas please ? Read More...
|
-
Hello,I have the questions, I have had installed the software/plugin in ordre : _Visual Studio 2005 Professional Edition (English version) _ LINQ Preview (May 2006).msi _ ADONETVN.msi _ AdoNetEdmDesignerCtp.msi _ dotnetfx3.exe _ vsextwfx.msi (Visual Studio 2005 extentions .NET Framework 30.(WCF& WPF), Novembre 2006 CTP) Then I load the sample of ADO VNext CTP from this directory : C:\Program Files\Microsoft SDKs\ADO.NET vNext CTP\Samples\CSharp I have the information : "This is unsupported version Read More...
|
|
|