linq-to-sql

Testing the context in asp.net mvc

I got pretty experienced with testing controllers, my question here is though, aren't we supposed to test the data context as well, and how ? I mean, there are a lot of relationships and constraints coming from the DB that simply testing controllers does not cover. On the other hand, testing against the DB is not considered a good prac...

Creating nullable association with Linq2Sql

I have a nullable foreign key in a database table. I want to create a relationship in Linq2Sql, but it doesn't allow me to create an association with a nullable foreign key and if i change the nullable value to FALSE within Linq2Sql the query crashes when a null is found. This should be creating a null child object, which should be fine....

Translate SQL query to LINQ

THIS USER HAS ALREADY ASKED THE EXACT DUPLICATE A FEW MINUTES AGO http://stackoverflow.com/questions/2552190/sql-and-linq-query PhotoAlbums table AlbumID Title Date Photos table: PhotoID Title Date AlbumID SELECT AlbumID, Title, Date, (SELECT TOP (1) PhotoID FROM P...

BindingSource And ComboBox: Combobox Binded on another Source

Hi, I would like to make Something in my form. I have a Binding source binded on Linq to Sql Class. The class Workorder contains one field Site. I would like to display The combobox with all the site, but selected on the site form my workorder. I'm clear? Julien ...

Error E_OUTOFMEMORY(0x8007000E) in Visual Studio 2010 RC

When I try to add a connection Linq to SQL with the OLE DB Provider : PostgreSQL OLE DB Provider I have an error message : Unspecified error: E_OUTOFMEMORY(0x8007000E) I don't understand what I've this message. ...

How the return type is determined in a method that uses Linq2Sql?

Hello, I've usually have difficulties with return types when it comes to linq. I'll explain by the following examples. Let's say I have a Table Products with ProductID, Name, Category, and Price as columns : 1) IQueryable<Product> public IQueryable<Product> GetChildrenProducts() { return (from pd in db.Products where pd.Ca...

adding validation annotators to model classes when using Linq-to-SQL

How should I add the following attrubute [Required(ErrorMessage="...")] to one of the model properties when my model classes are automatically generated. There is a solution here, but it seems to be working only on Entity Framework ...

linq-to-sql combine expressions

Is there any way I can combine list of expressions into one? I have List<Expression<Child, bool>> expList and trying to combine into one (AndAlso) and get Expression<Child, bool> combined = Combine(expList); Intended usage for combined expression is this: //type of linqFilter is IQueryable<Parent> linqFilter = linqFilter.SelectMany...

Can't set LinqDataSource InsertParameters from my code behind.

I have the following code that seems like it should set my insertParameter but everytime an insert happens it uses the default parameter. Do i need to do anything special to make this work? Codebehind: protected void SetInsertParams(object sender, LinqDataSourceInsertEventArgs e) { if (lbl_Personnel.Visible) { ...

Linq to SQL Web Service XML

I built a .NET web service connecting to an SQL Server database. There is a web service call GetAllQuestions() that will not change. I saved the result of GetAllQuestions to GetAllQuestions.xml in the local application folder and set it to content. Normally I would get the result of the web service like this: var myService = new SATSer...

Ria Services loading foreign keys with Linq-to-SQL

I have a database that consists of 5 tables : Course, Category, Location, CourseCategories, and CourseLocations. The last 2 tables just contain the two foreign keys. A Course has many-to-many relationships with both category and location. I am trying to load the data into a Silverlight app using Ria Services. My DB model is Linq-to-S...

Linq qurery with multiple where's

I am trying the to query my Status Update repository using the following var result = (from s in _dataContext.StatusUpdates where s.Username == "friend1" && s.Username == "friend2" etc... select s).ToList(); Insead of using s.Username == "friendN" continously is there anyway I can pass a list or...

Can LINQ-to-SQL omit unspecified columns on insert so a database default value is used?

I have a non-nullable database column which has a default value set. When inserting a row, sometimes a value is specified for the column, sometimes one is not. This works fine in TSQL when the column is omitted. For example, given the following table: CREATE TABLE [dbo].[Table1]( [id] [int] IDENTITY(1,1) NOT NULL, [col1] [nvarch...

Linq order by aggregate in the select { }

Here is one I am working on: var fStep = from insp in sq.Inspections where insp.TestTimeStamp > dStartTime && insp.TestTimeStamp < dEndTime && insp.Model == "EP" && insp.TestResults != "P" group insp by new { insp.TestResults, insp.FailStep } into grp select new ...

Where to insert 'orderby' expression in this linq-to-sql query

var result = db.PhotoAlbums.Select(albums => new PhotoAlbumDisplay { AlbumID = albums.AlbumID, Title = albums.Title, Date = albums.Date, PhotoID = albums.Photos.Select(photo => photo.PhotoID).FirstOrDefault().ToString() }); Wherever I try to put ord...

Cannot Translate to SQL using Select(x => Func(x))

I'm slowly learning the ins and outs of LINQtoSQL, but this is confusing me. Here is the statement I have: IQueryable<IEvent> events = (from e in db.getEvents() select e).Select(x => SelectEvent(x, null)); What the SelectEvent does can be explained in this answer here. I am not using the .toList() functio...

LINQ to SQL: making a "double IN" query crashes

I need to do the following thing: var a = from c in DB.Customers where (from t1 in DB.Table1 where t1.Date >= DataTime.Now select t1.ID).Contains(c.ID) && (from t2 in DB.Table2 where t2.Date >= DataTime.Now select t2.ID).Contains(c.ID) select c It doesn't want to run. I ...

How to wrap LINQ to SQL queries in stored proc?

LINQ to SQL internally generates SQL queries and fire on the database after submitting changes. Is there any way we can wrap all these queries in some stored procedure and execute this store proc everytime when anything gets inserted or updated in the database. Problem is only stored procedures are allowed to carry any insert or update ...

How does Select statement works in a Dynamic Linq Query?

Hello, 1) I've a Product table with 4 columns: ProductID, Name, Category, and Price. Here's the regular linq to query this table. public ActionResult Index() { private ProductDataContext db = new ProductDataContext(); var products = from p in db.Products where p.Category == "Soccer" select new Prod...

Get correct output from UTF-8 stored in VarChar using Entity Framework or Linq2SQL?

Borland StarTeam seems to store its data as UTF-8 encoded data in VarChar fields. I have an ASP.NET MVC site that returns some custom HTML reports using the StarTeam database, and I would like to find a better solution for getting the correct data, for a rewrite with MVC2. I tried a few things with Encoding GetBytes and GetString, but I...