linq-to-sql

LinqToSql query that spans a many-to-many relation?

Let say i have the following schema Content(Id, ....) TagContent(TagId, ContentId) Tag(TagId, Name) Suppose I'd like to select all content records that have tag with name "test". In SQL I would write: select Content.Id from Content join TagContent as TC on (TC.ContentId = Content.Id) Join Tag on (TC.TagId = Tag.Id) w...

Removing the WHERE clause in a Linq query

I have a table of product information with many bit columns. This table can be queried from an interface which has a checkbox for each column. The checkboxes are grouped into several related groups. For example, three of the columns describe the products suitability for various markets, being Automotive, Aviation and Marine. If none of...

Linq-2-Sql code: Does this scale?

I'm just starting to use linq to sql. I'm hoping that someone can verify that linq-2-sql has deferred execution until the foreach loop is executed. Over all, can someone tell me if this code scales. It's a simple get method with a few search parameters. Thanks! Code: public static IList<Content> GetContent(int contentTypeID, int feedID...

Save uploaded file to MemoryStream

Hi! How can I save a uploaded file (a pdf for example) to a MemoryStream? Thanks!! ...

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net

How can I convert this code LINQ to SQL in C # LINQ to SQL in Vb.net public IQueryable<Maestro_Clientes> GetMaestro_Clientes() { var q = from co in this.Context.Cli_Consumos group co by new { Servicio = co.Servicio, Cliente = co.Cli_Servicio.Cli_C...

Can't see the save data with linq?

Hi there I have the following code: // // POST: /PlayRoundHole/Create [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(FormCollection collection) { try { DB db = new DB(); PlayRound playRound = new PlayRound(); playRound.Pl...

Problem with linq to sql insert

Hello. My linq to sql insert class don't give a error and don't insert and i can't find out why. When i test the code in LinqPad i did work. public void CreateRole(string Role) { Roles role = new Roles() { Title = Role, }; data.Roles.InsertOnSubmit(role); try {...

Cannot insert duplicate key.

I am getting this error ... Violation of PRIMARY KEY constraint 'PK_Members'. Cannot insert duplicate key in object 'dbo.Members'. The statement has been terminated. When I try to use the Membership and Role Providers in ASP.NET MVC. It happens when calling the GetUser method from inside the RoleProvider. var member = System....

LINQ; forcing a new {} to return Iqueryable?

Hi there, I written a small query and in Linqpad its working well but (see below) Tariffs is not returned as Iqueryable, does anyone know how to fix this ? Basically see Tariffs = new ...., from v in House join gvt in (from t in MyTariffs where t.Id == 3 select t) on v.IdTariff equals gvt.Id select new { Id = v.Id, Tariffs =...

How to pass an unknown type to a function?

I am trying to write an Audit Log method that will log all changes in a Linq-To-Sql model. I want to get all changes an loop through each type of change an call my method that creates a log record for each type of object. I'm not sure if this is even possible. This is my code. I get an error when I try to pass in the type as typeof(o...

How to debug a linq to sql InsertOnSubmit statement?

The following code seased to work. db.DBUsers.InsertOnSubmit(new DBUser { AllTheStuff = valuesBeyondYourWildestDreams } ); db.SubmitChanges(); My guess is something changed at the database and the submit is failing because the mapping is off. As the linq visualiser isn't working for me (bonus points for fixing that) I want to find...

Linq's InsertOnSubmit not added to changeset

Related to http://stackoverflow.com/questions/1660200/how-to-debug-a-linq-to-sql-insertonsubmit-statement I Execute the following bit of code: db.DBUsers.InsertOnSubmit(new DBUser { Id = id, BrandCode3 = brandCode3.ToLower(), LoweredUsername = username.ToLower(), Username = username, CreationDate = date, Salt = salt, Pas...

How do I override DataContext.SubmitChanges()?

I want to override the SubmitChanges() method for my model. Whern I try to override I get a compiler error: cannot override inherited member 'System.Data.Linq.DataContext.SubmitChanges()' because it is not marked virtual, abstract, or override Is there anyway I can override this? Or do I have to create another method that r...

Linq: Simple Boolean function returns linq Exception

I have a Linq query that looks something like this: var query = from x in table where SomeFunctionReturnsBool() select; private bool SomeFunctionReturnsBool() { return true; } This returns and exception that says "SomeFunctionReturnsBool has no supported translation to SQL". I get that this is because it wants to treat "SomeFunct...

Linq to SQL - Security Exception

I have a simple website which is using C# and Linq to SQL to read an write to the DB. Everything works fine on my local box but now that I have setup on my hosting environment I am getting a "Security Exception" when trying to write to the DB, reading is fine. I have contacted the hosting company who say that they have configured everyth...

Joining and aggregating

I'm having trouble re-writing the following SQL as LinqToSQL: SELECT Sum(p.Impressions) as Impressions, Sum(p.Revenue) as Revenue, s.SiteUrl, u.UserName From PerformanceData p, Sites s, Users u where s.SiteID = p.SiteID and s.UserID = u.UserID and p.[Date] > @Start and p.[Date] < @End Group By p.SiteID, s.SiteUr...

Is having two Model objects for one table a common practice with LINQ-to-SQL / Entity Framework?

When using LINQ-to-SQL or Entity Framework, I can easily generate a class for each table which takes care of the CRUD basics: Info info = new Info(); info.Title = "testing"; db.Infos.InsertOnSubmit(info); db.SubmitChanges(); And when I make structural changes to a database table, I can easily regenerate the table's model class (simpl...

LINQ to SQL Could not find key member. Only fails on server.

I have a scenario where I am inheriting from an abstract class in my partial linq to sql auto generated class implementation. My base abstract class has an abstract property called ID which I have flagged inside my LINQ to SQL model with the instance modifier override. This works fine locally without any issues. I have also done some dev...

Linq to SQL and MySQL database

Is it possible to use all features of Linq to SQL for a MySQL database? ...

Username/Password Database Checking

How can I improve this username/password checking? [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(FormCollection collection) { var users = (from p in _dataContext.Users where p.Name == collection["Username"] && p.Password == collection["Password"] select p); if (...