linq-to-sql

linq to sql generates members as non-public

I have 2 tables related by a foreign key. The problem is the children of one the father-entity are created as non public members and i cant reach them in code. ...

LIKEs and ORs and stuff in Linq

I'm trying to write a linq-to-sql query using || that behaves the same way as the OR in SQL when combined with a LIKE/Contains. SQL: SELECT * FROM Users WHERE GroupNumber = 'A123456' OR (FirstName like 'Bob%' AND LastName like 'Smith%') This will result in everyone with a name like "Bob Smith" as well as everyone with a GroupNumber e...

Linq-to-Sql case insensitive code generation

Is there a way to configure the way linq-to-sql generates the property names in a stored precedure result. I want them all upper case independent from the upper and lower case that were used in the stored procedures. ...

Entity Framework/L2S creating new table in DB and Load it to the context?

Is it possible to create a new table programatically in EF or L2S and load it to its context? We have this application that requires to create a table at runtime and do some CRUD activities to that table. Is this possible? If not, any advice? ...

Retrieve fewer table fields using Linq To Sql lambda expressions

I'd like to know how to get a subset of data from a table using Linq To SQl Lambda expressions... Let's say I have a table tbl_Product, with fields ProductId, ProductCode, ProductName, Description, WhyBuyCopy, how do I get only the first three fields when the others are not needed given that retrieving all data takes a second longer (ch...

LINQ join and group

How to expand this query: public Dictionary<int, List<TasksInDeal>> FindAllCreatedTasks() { return (from taskInDeal in db.TasksInDeals where taskInDeal.Date > DateTime.Now && taskInDeal.Date < DateTime.Now.AddDays(7) group taskInDeal by taskInDeal.CreatedByUserID into groupedDemoClasses ...

In Linq to SQL, why does assigning a related entity create a ChangeSet insert ?

Why is the following adding an Insert (of the new Address) to the DataContent ChangeSet, and how can I stop it from doing so? var db = new DataClasses1DataContext(); var a = new Address(); a.StateProvince = db.StateProvinces.First(); Console.WriteLine(db.GetChangeSet().Inserts.Count); ...

SqlDependency throwing Invaild Operation exception

In our project we are invalidating the cache based on the change in the query output. This is implemented using change notifications. In the Global.asax file in the Application Start block we have also added SqlDependency.Start(ConnectionStr). But still its throwing the following invalid operation exception Message "When using SqlDepend...

LINQ To SQL: simpest way to rebuild dbml file

What is the easiest way to rebuild a dbml file with Visual Studio 2008? There is no "refresh" option in popup menu as in the Entity Framework wizard. I use bat file (that executes sqlmetal) from the project nowadays. ...

LINQ to SQL Select new as Custom Type not working!

Hi, can anyone tell me why this doesnt work? public class GeocodeCoord { public string Outcode { get; set; } public int X { get; set; } public int Y { get; set; } } List<GeocodeCoord> _geocode; using (MyDataContext db = new MyDataContext()) { _geocode = db.Geocodes.Select(g => new GeocodeCoord { g.postcode, g.x...

Linq 2 SQL LoadWIth loading multiple (unnecessary) joins

I have a following classes class User { [Column]public int Id; [Column]public string Name; [Column]public Company Company; } class Company { [Column]public int Id; [Column]public string Name; [Column]public Address Address; } class Address { [Column]public int Id; [Column]public string Street; [Col...

Casting the results of linq-to-sql

Working with interfaces, we commonly have a var or an IQueryable that is going to return a set of data objects that we will then cast to the interface and return as a List or IList, like this: var items = from t in SomeTable where t.condition == true select; return items.ToList( ).Cast<SomeInterface>( ).ToList( ); NOTE: items.Cast...

What is the difference between Entity Framework and LINQ to SQL by .NET 4.0?

I was checking 2nd edition of Professional ASP.NET MVC and realized EF replaced LINQ to SQL. I am familiar to LINQ to SQL from the first book but I know nothing about EF. Anyway while reading the code, it seems like nothing has changed except the name. Same old repository, same old functions. I did a little research. I know LINQ is not...

Linq to Sql for counting and averaging a set of data (no grouping)

I would like to execute a Linq to Sql statement that captures the count and average in a (filtered) set of data. What I have works, but it requires two queries to the database when it should be possible in one query. Interestingly enough, I can get one query to be emitted when I use a group by clause. For example: select count(*), avg...

DataContext SubmitChanges in LINQ

Is it safe to call SubmitChanges() when you are not sure whether the data has changed? What does it actually do? ...

How to build a query by passing the columname and columnvalue as parameter using LINQ

Hi All, We tried using the below code snippet but showing the syntax error. var query = (from def in entity.Defect.Where("Owner == @0", "rochs") select def).ToList(); Thanks in Advance ...

LINQ to SQL and SqlDependency

Hi All, Are there any implications of using SqlDependency and LINQ to SQL together. Or do we have to take care of some things specially to make them work properly? In our application we are using LINQ to SQL as an ORM and business logic is in the Stored Procedures. We cache the output of the SPs and create SQLDependency. Whenever the o...

LINQ to SQL: how to retrieve auto generated integer id primary key

I suppose the question was asked before (it's so general) but I can't find the answer. How can I retrieve auto generated integer primary key value after I inserted a new row and called "SubmitChanges" ? I need to know the key exactly on the client-side 'cos I'm going to use this value further for calculations. When unique key is Gui...

Performance Improvement for Insert Statement

On my ASP.NET MVC application I'm running a couple of inserts at once that can insert 10000 or more lines and update a few others. This process is taking a long time but I can't escape the insert because that's exactly what I was asked to do. Right now I'm running Sql Server Profiler and it takes almost 20 minutes to insert this bunch of...

How to return rows with max value one column grouped by another column?

this is data id code status 1 1 5 2 1 6 3 2 8 4 2 9 5 2 12 6 3 15 7 3 19 8 3 13 what I need as a result is this: id code status 2 1 6 5 2 ...