I need to do a left join on multiple conditions where the conditions are ORs rather than ANDs. I've found lots of samples of the latter but am struggling to get the right answer for my scenario.
from a in tablea
join b in tableb on new { a.col1, a.col2 } equals new { b.col1, b.col2 }
group a by a into g
select new () { col1 = a.col1, c...
Linq to SQL makes use of ROW_NUMBER() for paging purposes, i.e. When you use Skip() and Take().
However, I can't seem to find a way of actually accessing ROW_NUMBER() values myself in the query. I need to find the ROW_NUMBER() of a record within a query (without bringing all the records back).
I've done this successfuly in T-SQL and Li...
When you setup linq, it maps all your tables to objects, I get that.
Now what happens when your linq query is inner joining with another table?
I read on here that it returns an anonymous object?
What if I have an object that maps to the columns in the inner join of 2 tables, how do I map?
Just looping through the collection as if it...
In my database I have stored images in the "image" data type, showing up as a binary code.
I now want to retrieve all images from one column and diplay them on a asp.net page with C#.
databaseDataContext db = new databaseDataContext();
var images = from Picture p in db.Pictures
select p.pictureThumb;
then I use t...
Does anybody know an example of correct many-to-many implementation in Linq-to-Sql?
Usually i use intermediate entity (e.g. CustomerProducts) in DataContext, and join it at every query.
The idea is to hide intermediate entity from object level by adding custom properties to partial classes - use collections like IEnumerabe Customer.Prod...
I'd like to allow some of our business analysts to write in linq instead of SQL where applicable. Corporate would never go for allowing linqpad to be installed, so where would I start on learning how to allow say simple linq queries or expressions in vs2008 project?
Is there sometype of eval() function for .net that would compile and ru...
I have this:
Dim compareAddress1 = (From d In db.Addresses Where d.Address1.Equals("a") And _
d.Address2.Equals(Nothing) And _
d.City.Equals(Nothing) And _
d.POBox.Equals(Nothing) And _
d.PostalCode.Equals(Nothing) And _
d.ZipCode.Equals(Nothing))
Dim compa...
I got that "ugly" linq to sql query:
Dim f = (From d In db.Addresses Where ((_address.Address1 Is Nothing AndAlso d.Address1.Equals(Nothing)) OrElse (_address.Address1 IsNot Nothing AndAlso d.Address1.Equals(_address.Address1))) And _
((_address.Address2 Is Nothing AndAlso d.Address2.Equals(Nothing)...
Ok,
Last time I posted this (last week), I didn't describe the problem correctly. I have created a quick sample of this problem. Querying local collections work fine with you are using it as part of the base query. The problem I am finding is using it with part of a sub query. For example.
This is fairly hard to describe without giv...
I've two tables (1:N)
CREATE TABLE master (idMaster int identity (1,1) not null,
TheName varchar( 100) null,
constraint pk_master primary key(idMaster) clustered)
and -
CREATE TABLE lnk (idSlave int not null,
idMaster int not null,
constraint pk_lnk_master_slave(idSlave) primary key clustered)
link between Master.idMaster and ...
I need to update values but I am looping all the tables values to do it:
public static void Update(IEnumerable<Sample> samples
, DataClassesDataContext db)
{
foreach (var sample in db.Samples)
{
var matches = samples.Where(a => a.Id == sample.Id);
if(matches.Any())
{
var match = matches.Fi...
If i have an object of type Photo and a Result set which is sorted in a particular order, is there a way for me to get the position of the current Photo object in the result set. and then get all objects that would follow it?
...
I have my application working fully on my development machine and storing data all okay on a SQL 2008 database, how every when I deploy the application to my server, which is running SQL 2008, and the model is stored in the database the date fields do not accept an English date format.
e.g.
13/08/2009
fails
...
if the code look like:
dim db = new context.mytable
db.somefield = something
context.insertonsubmit(db )
try
context.save
catch ex as exception
''----????
end try
how to I remove db from the context if it goes into the catch?
...
Hi All,
I have a Dynamic Data Website for edit, update and delete data. As we know, the dynamic data website uses LINQDatasource control for DB operations. For delete, i am using Stored Procedure instead of using default LINQ that returns a int on successfull delete. i have configured my LINQ to SQL class to use the stored procedure for...
I have a MVC application that I'm near completing. But I have a situation that cannot figure out the syntax for.
What I want to do is to sort on two columns When I use the syntax below, it sorts by one column, then the next.
public IQueryable<vw_FormIndex> FindAllFormsVw(int companyIdParam)
{
return _db.vw_FormInd...
How do you lazy load nested lists without actually executing the query? Using a very basic example, say I have:
class CityBlock {
IList<Building> BuildingsOnBlock;
Person BlockOwner;
}
class Building {
IList<Floor> FloorsInBuilding;
}
class Floor {
IList<Cubicle> EmployeeCubicles;
}
Class Cubicle {
System.Gui...
Hi,
Say I am selecting rows from my article table, but I want to dynamically sort by specific columns and sort by des/asc.
Say my method signature looks like:
public List<Article> GetArticles(SortBy sort, SortOrder order)
{
}
Is there a way to do this with linq-to-sql?
...
I'm trying to figure out how to create the LINQ-to-SQL for the following SQL and not having any luck. Any help would be appreciated. C# code for the response is prefered. Also, indexes other than PKey not shown for brevity.
Table Schema:
CREATE TABLE [dbo].[FileHashes](
[ID] [uniqueidentifier] NOT NULL,
[FileName] [nvarchar](255) NU...
Hey,
I noticed that disposing and re-creating a DataContext is way faster than refreshing it with RefreshMode.OverwriteCurrentValues, which should effectively be the same.
While this causes my application to spike at 100% CPU for several seconds
dbc.Refresh(RefreshMode.OverwriteCurrentValues, dbc.Property);
the following code doesn...