linq to sql: join multiple columns from the same table
This is the only way I was able to get it to work (in c#). var qry = from t1 in table1 join t2 in table2 on new {t1.ID,t1.Country} equals new {t2.ID,t2.Country} …
This is the only way I was able to get it to work (in c#). var qry = from t1 in table1 join t2 in table2 on new {t1.ID,t1.Country} equals new {t2.ID,t2.Country} …
You need to import the namespace into your view by adding @using System.Data.Linq at the top of your view. However if you want it in all your views then you need to add <add namespace=”System.Data.Linq” /> to the web.config in your Views folder: <system.web.webPages.razor> <host factoryType=”System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35″ /> <pages pageBaseType=”System.Web.Mvc.WebViewPage”> <namespaces> <add … Read more
I have written one for my needs that converts a lookup table of your choice to an enum: Put this code inside an EnumGenerator.ttinclude file: <#@ template debug=”true” hostSpecific=”true” #> <#@ output extension=”.generated.cs” #> <#@ Assembly Name=”System.Data” #> <#@ import namespace=”System.Data” #> <#@ import namespace=”System.Data.SqlClient” #> <#@ import namespace=”System.IO” #> <#@ import namespace=”System.Text.RegularExpressions” #> <# … Read more
Unlike most types which implement IDisposable, DataContext doesn’t really need disposing – at least not in most cases. I asked Matt Warren about this design decision, and here was his response: There are a few reasons we implemented IDisposable: If application logic needs to hold onto an entity beyond when the DataContext is expected to … Read more
See this existing thread. If you decide to do it by hand, Linqpad should be useful.
AFAIK, this isn’t supported by the object model. However, LINQ supports a method to execute a query (strangly enough called DataContext.ExecuteQuery). Looks like you can use that to call a arbitrary piece of SQL and map it back to LINQ. You won’t be SQL free because of the embedded SQL, but you won’t have to … Read more
Yes it is, so here’s the entry from my blog: The NOLOCK hint is essentially the same as wrapping a query in a transaction whose “isolation level” is set to “read uncommitted”. It means that the query doesn’t care if stuff is in the process of being written to the rows it’s reading from – … Read more
Entities can be created outside of queries and inserted into the data store using a DataContext. You can then retrieve them using queries. However, you can’t create entities as part of a query.
Assuming that your LINQ to SQL (L2S) classes are auto-generated and reflects your underlying database, the short answer is: Don’t expose IQueryable of any of your L2S classes – it would be a Leaky Abstraction. The slightly longer answer: The whole point of Repositories is to hide data access behind an abstraction so that you … Read more
Aristos, here’s the thing I’m having an issue with. You posted a question to our groups and we had a nice, 23-long email exchange. You insisted that SubSonic 3 has problems and you asked me why I haven’t fixed this “slow, broken tool”. I tried to explain to you that, with 233 tables, SubSonic has … Read more