I have generated linq to sql entites but cannot figure out how to assign null to a nullable column. whenever i try to assign null to it it says "there is no implicit type conversion between int and ". BTW the type of the field is int? and the database column is also nullable.
...
I like LINQ to SQL, but it seems like the classes it generates are tightly coupled to the database they are stored in, which seems like a Bad Thing.
For example, using ye olde Northwind database, if I create the dbml with the Products table, a Product class is generated. I can use this class in any other tier, which is all well and goo...
Is it possible to extend LINQ-to-SQL entity-classes with constructor-methods and in the same go; make that entity-class inherit from it's data-context class?--In essence converting the entity-class into a business object.
This is the pattern I am currently using:
namespace Xxx
{
public class User : Xxx.DataContext
{
pub...
Hi,
I have an ASP.NET MVC view which contains checkboxes for user-defined categories.
<td><% foreach (Category c in (List<Category>)ViewData["cats"]) {
if (selCats.ContainsKey(c.ID)) { %>
<input name="CategoryIDs" type="checkbox" value="<%=c.ID %>" checked="checked" /> <%= c.Name%><% }
else { %>
<inpu...
What are your favorite ways to encapsulate LINQ to SQL entity classes and data-context classes into business objects?
What have you found to work in a given situation?
Have you invented or taken to any specific patterns?
...
Hi all,
I have two LINQ objects which have exactly the same columns and I would like to be able to update one with the fields from the other. I first create a new object from some data in a file, then I query the database for an existing item with the same ID. What I would like to be able to do is update the existing objects details w...
What is the best way to delete a database record using LINQ when I have the primary key?
...
Is there any plans for Microsoft to support LINQ to SQL beyond MS SQL server?
...
The one thing that LINQ seems to be missing for me is a way to reference columns by text string. For example, I have a typical GridView set up with sorting like this (the DataSource is bound to a LINQ query in the code-behind):
<asp:GridView ID="MyGridView" runat="server" AllowSorting="True">
<Columns>
<asp:BoundField DataFi...
I have a project with a number of different classes querying and modifying data in a common set of tables. I've set up a .dbml file which provides us with a DataContext class. My question is whether a single instance of the DataContext should be used by all objects, or whether multiple instances are safe to use. I'm also wondering about ...
I am trying to get LINQ to SQL to persist changes to an attached object wherein the backing table has a DateTime column that I think should function for row versioning, as described here.
The table looks like this:
CREATE TABLE [dbo].[client](
[client_id] [int] IDENTITY(1,1) NOT NULL,
[client_address1] varchar(100) NULL,
/* snip */
[mo...
I work on a web game , I use asp.net mvc, linqtosql.
I have 3 tables that store default game values: DefaultRegions, DefaultSubRegions and DefaultCountries. These 3 tables are related to each other thanks to primary / foreign keys.
I need to copy the values of these tables into 3 tables called Regions, SubRegions and Countries when som...
How do you insert/update a column through Linq To SQL and Linq To SQL use the default values? In particular I'm concerned with a timestamp field.
I've tried setting that column to readonly and autogenerated, so it stopped trying to put in DateTime.MinValue, but it doesn't seem to be updating on updates.
...
I have looked over the Repository pattern and I recognized some ideas that I was using in the past which made me feel well.
However now I would like to write an application that would use this pattern BUT I WOULD LIKE TO HAVE THE ENTITY CLASSES DECOUPLED from the repository provider.
I would create several assemblies :
an "Interfaces...
I'm trying to figure the best strategy about how to organize DataContexts. The typical DB we work has between 50 and 100 tables usually in third-normal form and with many relations between them. I think we have two options:
Put all tables in a single context. This will ensure that anything we do will be committed in the correct order i...
I'm trying to enable SqlCacheDependency through my StructureMap IoC, I'm using LinqToSql I have the code done to take care of the Linq Caching but not quite sure how to go about setting up the SqlCacheDependency as it requires putting this in a global.asa file
void Application_Start(object sender, EventArgs e)
{
string connectionSt...
Disclaimer: I've solved the problem using Expressions from System.Linq.Expressions, but I'm still looking for a better/easier way.
Consider the following situation :
var query =
from c in db.Customers
where (c.ContactFirstName.Contains("BlackListed") ||
c.ContactLastName.Contains("BlackListed") ||
c.Add...
I just downloaded MVC and I am going through a tutorial. Everything goes fine until I try to declare a DataContext object.
My dbml is named db.dbml (tried another on named test.dbml) and when I try this:
public dbDataContext db = new dbDataContext();
I get:
The type or namespace name
'dbDataContext' could not be found ...
Am...
I have a web application that comprises the following:
A web project (with a web.config file containing a connection string - but no data access code in the web project)
A data access project that uses LINQ-SQL classes to provide entities to the web project UI (this project has a settings file and an app.config - both of which have con...
Given an EmployeeId, how can I construct a Linq to Sql query to find all of the ancestors of the employee? Each EmployeeId has an associated SupervisorId (see below).
Entity Definition:
Sample Table Data:
For example, a query of the ancestors for EmployeeId 6 (Frank Black) should return Jane Doe, Bob Smith, Joe Bloggs, and Head H...