linq-to-sql

Do you create multiple .dbml/.edmx file for large database when using LINQ2SQL or Entity Framework?

When creating .dbml/.edmx for a database which has a lot of tables, do you use multiple .dbml /.edmx file or just a single giant file? Any pro/cons for splitting the model into multiple file? Thanks, J.W. ...

How can I do this LINQ query on a condition that something not exist in a table?

In our database, a file is "Processing" if the column "Pending" is set to false on the FileTable and that files FileID doesn't exist in the Transaction table. How can I construct a LINQ query that basically says, where f.Pending == False && (f.ID !=exist in db.Transactions.FileID) The portion in the parenthesis is what I'm not sure ho...

How do you implicitly convert a string value to an enumeration using LinqToSql?

I asked a previous question about mapping an enumerated value on a table using LinqToSql and the answer was to use the O/R Designer to set the type to global::MyNamespace.TMyEnum. That works OK if your enumeration is based on an integer. But what if your enum is based on a string value? The most obvious application of this is: public...

How to prevent memory overflow when using an IEnumerable<T> and Linq-To-Sql?

This question is related to a previous question of mine That's my current code IEnumerable<Shape> Get() { while(//get implementation yield return new Shape(//... } void Insert() { var actual = Get(); using (var db = new DataClassesDataContext()) { db.Shapes.InsertAllOnSubmit(actual); ...

Confusing LINQ statement

Hi, I am trying to craft a LINQ statement as follows: The result should follow between two dates (today basically) OR the result should have a "batchstatus" column that equals false (hasn't been verified yet) the result should have a "ready" column that equals true (is ready to be verified). So verifiers can see all data from today ...

Need help with LINQ query and ASP.NET MVC?

My repository returns a list of Accounts. Each account has a date and a MoneySpent decimal amount. So, I have my list of Accounts and in my controller I'm trying to process this list a little. I want to have an object which contains the string name of all the months in my Account list and a Sum of all money spent for that month. Here...

Is there another way to create a contract for a LINQ-to-SQL model class?

I have two classes, for this example, that are partial classes against LINQ-to-SQL model classes. public partial class Foo { public bool IsValid { get { return (GetRuleViolations().Count() == 0); } } public IEnumerable<RuleViolation> GetRuleViolations() { yield break; } partial void OnVal...

Selecting columns in DataLoadOptions

I'm using the DataLoadOptions to retrieve the User that modified a Customer's details, DataLoadOptions dlo = new DataLoadOptions(); dlo.LoadWith<Customer>(c => c.ModifiedBy); However, I only want the User's ID and FirstName and not all the columns. Is there a way to specify the columns you want in the DataLoadOptions? Tables: Custo...

How can I set the value of a column for every row in a table using LINQ?

Lets say I have a File table with the column, "File_ID". How can I write a quick LINQ query/statement to set every "File_ID" in the File table to "1"? I'm using LINQPad in Statement mode, but that doesn't matter really. ...

How can I query this hierarchical data using LINQ?

I have 3 kinds of objects: Agency, BusinessUnit and Client (each with their own respective table) In terms of hierarchy, Agencies own BusinessUnits, and BusinessUnits own Clients. I have 3 C# POCO Objects to represent them (I usually select new {} into them, rather than use the LINQ generated classes): public class Agency { public...

Is there an implementation of IQueryable over DbDataReader?

I have a lot of existing code which uses raw ADO.NET (DbConnection, DbDataReader, etc). I would like to transition to using LINQ to SQL for new code, but for now put both the existing and new code behind a unified set of Repository classes. One issue I have is this: I would like the Repository classes to expose result sets as IQueryab...

How is Entity Programming changing the way we think about databases?

I am wondering how the shift from relational, table-based design to object-oriented, entity-based design is affecting the mindset of developers writing the next wave of applications. Given the nature of the debate swirling around the Entity Framework and Linq to SQL, is it premature to be thinking about entity-driven design? Are we bri...

Web.Config file and Linq to Sql changing its place

I'm having a strange issue with my project. It was a Web Site that is now converted to a Web Application that is in a solution. Initially classes were setup using Linq to Sql .dbml file, which stored its connection string in /MyProject/web.config. Now the project ('Web Application') is in a solution and when I modify the Linq to Sql d...

Linq to sql truncating string returned by Stored Procedure

I have asked this question before. but i was not able to get any answer. may be i wasnt very clear. let me give some more details. I have a SP which returns a long string. here is dbml file code [Function(Name="dbo.spX")] public ISingleResult<spXResult> spX([Parameter(DbType="VarChar(8000)")] string str) { IExecuteResult result = t...

How do I ensure that a table triggered SP has completed to use the data?

I have within my Sql Server 2008 database a trigger which will run on insert and update to populate a calendar table with dates calculated from the date info in the first table. (i.e. start date, end date, repeating sequence information). I am using ASP.Net MVC using Linq to Sql to access the Database. My first view is collecting the da...

Is LINQ to Everything a good abstraction?

There is a proliferation of new LINQ providers. It is really quite astonishing and an elegant combination of lambda expressions, anonymous types and generics with some syntax sugar on top to make it easy reading. Everything is LINQed now from SQL to web services like Amazon to streaming sensor data to parallel processing. It seems like s...

Dynamic Linq To Sql With ComboBox and Column.Contains

I have a text box, combo box, button and DataGridView on a form that is used to search and return customer information from a MSSQL view (vCustomer). It works great, but I know my code can be more efficient. The four items in the combobox represent columns to search. Is there a simple way of converting the following to dynamic LINQ to...

Linq To Sql Entity Operations

I'm trying to use: // this is a BreakHistory class from the ADO.NET Data Entity Model _entities _entities.AddToBreakHistory(this); _entities.SaveChanges(); and I'm getting "An entity object cannot be referenced by multiple instances of IEntityChangeTracker." error I'm thinking that my update code: _entities.ApplyPropertyChanges(this...

Is there anyway to have server explorer use the connection string in my web.config?

When I'm adding items from the database into my dbml from the server explorer it complains that the connection strings aren't the same and it won't add my object until they are the same. Once I say OK update my connection string it trashes the formatting of my web.config and I need to remember to switch it back to the correct connection ...

Is there an easy way to convert System.Data.DataTable to a linq entity?

Is there an easy way to take a DataTable and cast it to its entity type? I have an Entity called Samples, however through layering this is at one point returned as a DataTable - i woud like to be able to cast this to its entity type if possible? Thanks ...