linq-to-sql

How can you tell if a stored procedure does not return results when using vb.net and linqtosql?

I have a linqtosql dbml where I dropped a stored procedure into the designer interface. Stored procedure name: GetUser(@userid int) Select * from users_tbl where userid=@userid Now in the code I want to do something like this: Dim db as new UserDataContext Dim myuser as users_tbl = db.GetUser(1) How can I tell if GetUser returned...

LINQ to SQL, get most recent records for given ID

intHi, Pretty new to LINQ. I have a Ratings table. A User adds a set of Ratings for an Entity There can be more than one Rating set for an Entity per User. For example, let's say the Entity is a car. The car is rated on Appearance and Performance. And a User can rate the given car's appearance and performance more than once. So my ...

How can I update with LINQ all records that have equal value?

Hi all. Can anybody help me with this: I want select all records from datatable which have for example sid=123 and after that save they with sid=456. How can I do this with LINQ? ...

LINQ to SQL join 3 tables and select multiple columns and also using Sum

Hi, I have three tables Student, TimeSheet and TimeRecord. Talbe columns: Student : StudentId, FirstName, LastName TimeSheet: TimeSheetId,StudentId, IsActive TimeRecord: TimeRecordId,TimeSheetId, BonusHour(type int), CreationDate Table relationship: Student 1:N TimeSheet (FK StudentId) TimeSheet 1:N TimeRecord (FK TimeSheetId) ...

Repository pattern: One repository class for each entity?

Say you have the following entities defined in a LINQ class: Product Customer Category Should I have one repository class for all: StoreRepository ... or should I have: ProductRepository CustomerRepository CategoryRepository What are the pro & cons of each? In my case, I have several "applications" within my solution... the Stor...

LINQ-to-SQL - How to Include Property

I have the following example: using (MyContext context = new MyContext()) { var query = from entityA in context.EntityA.Include("TestProperty") join entityB in context.EntityB on entityA.Id equals entityB.EntityAId join entityC in context.EntityC on entityB.Id equals entityC.EntityBId ...

Avoid LINQ with Let keyword doing self-loop

I have three tables Student, TimeSheet and TimeRecord. Talbe columns: Student : StudentId, AssignedId, FirstName, LastName TimeSheet: TimeSheetId,StudentId, IsArchive, IsComplete TimeRecord: TimeRecordId,TimeSheetId, BonusHour(type int), CreationDate Table relationship: Student 1:N TimeSheet (FK StudentId) TimeSheet 1:N TimeRecord...

LINQ to SQL sum null value

Hi, I have the following query, I'd like to sum the NULL value also. Some TimeSheet don't records in TimeRecord and some tr.TimeIn and tr.TimeOut are NULL. The query select only TimeSheet that has reords in TimeRecord. How I can have it select everything, and sum up the NULL value as well. So, the SUM of NULL will be just zero. Table ...

Simple Transactions

I have 2 linq 2 SQL statements I'd like to be in a transaction (the SQL server is remote, outside firewalls etc) all other communication works but when I wrap these 2 statements in a TransactionScope() I begin having to configure MSDTC which we did, but then there are firewall issues (I think) is there a simpler way? the basics of what ...

Inlcude conditional checking in query with LINQ to SQL

Suggestion either in C# or VB.NET are welcome. Table relationship: Student 1:N TimeSheet (FK StudentId) TimeSheet 1:N TimeRecord (FK TimeSheetId) Dim query = From s In db.Students _ Let pair = (From ts In db.TimeSheets _ Join tr In db.TimeRecords On tr.TimeSheetId Equals ts.TimeSheetId _ Where ...

Add Conditional Join Dynamically with Linq

I have a basic search control which lists companies from a CRM depending on predefined search/filtering criteria supplied by dropdowns. The default selection is "ALL" for each DropDown, otherwise the user chooses a specific item(s). I'd like to be able to construct a Linq query dynamically based on the selections. Out of the 5 selectors ...

How can update an entity using Linq-to-SQL?

I have the following class that can create/delete and list entities: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; namespace Backend.Models { public class PaisRepository { private EnviosDataContext db = new EnviosDataContext(); public IQueryable<Pai> Fin...

cannot convert from 'System.Data.Linq.Binary' to 'System.IO.BinaryReader'

my table column is: AttachContent varbinary (max) when i try to retrieve the data and i get this below error, i am using linq cannot convert from 'System.Data.Linq.Binary' to 'System.IO.BinaryReader' ...

Linq to Sql Distinct is returning multiple rows

How can I produce something like this with Linq? I'm trying to work something out, this is related to my other post, but my distinct keeps coming back with more rows than expected http://stackoverflow.com/questions/3533629/add-conditional-join-dynamically-with-linq select distinct c.CompanyID, c.CompanyName from Company c left join Com...

Linq to SQL vs Entity Data Model: Getting a stored proc to run

Was I was previously messing with Silverlight and RIA, I was using a an ADO.NET Entity Data Model and domain context. I'm teaching myself how to run a stored procedure from RIA, and could not get it to work with the previous setup so I then started to try out using the LINQ to SQL method. I did the following: Added the DBML Drag and d...

ASP.NET - How to properly split a string for search?

I'm trying to build a search that is similar to that on Google (with regards to exact match encapsulated in double quotes). Let's use the following phrase for an example "phrase search" single terms [different phrase] Currently if I use the following code Dim searchTermsArray As String() = searchTerms.Split(New String() {...

linq to sql- bug- vs08 any remedy?

all the table names are appended with a 's'?? like table test will appear as tests in the coding.. please help is this a known bug, or ? ...

Selecting dynamic types using Linq to SQL

I would like to select from a table using linq to sql without knowing what that table is until runtime, something like Type t = Type.GetType(myString); var results = from o in context.t select o; Obviously this doesn't work, but I was wondering if there was a way to do this. ...

LINQ to SQL most recent set of records for a given ID?

This one should be easy. I have a Reviews table with records. The columns are EntityID, UserID, Body, DateModified. A User can submit multple entries for an Entity. I want to select all the Reviews that are the most recent entries for a given entity per UserID. So the table might look like this: EntityID UserID Body DateMo...

LINQ to SQL join two tables to select parent table twice based on two different columns from child table

I'd like to get suggestion in both C# and VB.NET I have two tables Employees and CafeLogs. Some employees can be cashiers and also customers at the Cafe shop. Table structures: Employees: EmployeeId(PK) , FirstName, LastName CafeLogs: LogId (PK), CashierId, EmployeeId, Value, => CashierId and EmployeeId are the data from column Emp...