linq-to-sql

Current Logged in User as Default user in LINQ to SQL

I am using LINQ to SQL and I would like to set the default value of a filed called UserName to be the logged in user name. So I can do the following, which works partial void OnCreated() { this.UserName = Thread.CurrentPrincipal.Identity.Name; } However I'm not happy about using the Thread.CurrentPrincipal.Identity.Name within my...

How to update a BindingSource based on a modified DataContext

In my application, I extract the Data of a Linq To SQL DataContext into a dictionary for easy use like so: Jobs = dbc.Jobs.ToDictionary(j => j.Id, j => j); Then I bind this dictionary to a BindingSource: bsJob.DataSource = jobManager.Jobs.Values.ToList(); I refresh the DataContext and the Dictionary regularly for when new Jobs are ...

Direct Access to SQL with Silverlight.

I am new to .NET in general, so I hope this isn't too n00b of a question. I'm looking to write a Silverlight app that interacts with a MSSQL DB using LINQ. Do I absolutely, positively have to use a seperate WCF service? It seems there are security implications, but this would be on a completely trusted network. Thanks in advance ...

LINQ to SQL architecture. What is best?

Hi all, This question is sort of a pool. We are trying to identify the best archtecture while using a ORM like LINQ to SQL. The archture we are defining is for sort of framework that other applications will access either trough directly referencing the DLL or through a webservice. We have .NET apps and PHP apps. The possibilities are: ...

Setting the LinqDataSource Where Clause using DateTime Column

In c#.net I have the following DataSource setup that I am trying to dynamically assign a WHERE clause to in the code behind... <asp:LinqDataSource ID="LinqDataSource1" runat="server" ContextTypeName="MyNameSpace.DataClasses1DataContext" TableName="MyTableWithADateTimeColumn" > </asp:LinqDataSource> The code behind looks som...

Are Linq to SQL and Linq to Objects queries the same?

If we abstract out the DataContext, then are L2S and L2O queries identical? I already have a working prototype which demonstrates this, but it is very simple and wonder if it will hold up to more advanced querying. Does anyone know? ...

Grouping and count with LinqToSQL

I have an artist table and a style table. artist table: id name styleid style table id name An artist has a style id I'm trying to return a style summary which includes style id, style name and number of artists belonging to that style. I've got the following statement which gets me the id and number of artists but I cant see how...

Case Sensitive Where Clause in LINQtoSQL?

I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table using LINQtoSQL. Let's say if a tag 'BEYONCE' exists in tags, then I want that I can add 'beyonce' or 'BeYOnce' but not 'BEYONCE' again. Here is the LINQ query i have written: From t In Context.Tags Where String.Equals(t.Tag, myTag, StringComparison.Ordinal) ...

LinqDataSource query help

Hi All, I know LINQ doesn't have the SQL IN clause but rather uses "contains". Can I use this on a LinqDataSource? I want to write a simple query that is equivelent to this: SELECT * FROM tableA WHERE tableA.requestType NOT IN (5,6,7,8) AND tableA.someBitField IS NULL. Is this possible using the LinqDataSource out of the box? Thanks fo...

Moving records up and down with Linq to SQL

I need to implement a function for moving records up and down (sorting) and saving the sortorder with Linq to SQL. I am using SQL Server 2000 but I might be able to upgrade if there is a solution for it with a newer version of SQL Server. I would love to hear any thoughts you might have on how to do it. ...

how to serialize Linq-to-SQL DataLoadWith.LoadWith when using it thru WCF?

In one of our project we're using Linq-to-SQL to get data from our database. There are a lot of tables that have references to others. We're using the LoadWith method to get a hold of that data. The data is than serialized and send to a client application using WCF. On the cliend the references are gone. When stepping thru the code and w...

Implementing linqtosql partial DataContext class - how to inspect before/after values

I'm trying to extend the linqtosql classes generated by the VS designer and need to determine if the value of a specific field has changed. Is there a way for me to access the before and after values for a field in the DataContext Update method for a table/entity? Here's my code: public partial class DataClassesDataContext { parti...

When using linqtosql, and inner joining, can you return only a subset of columns?

When using linqtosql, and inner joining, can you return only a subset of columns or does it pull in all the column/properties? Sometimes you need just 2-3 columns, having it pull back all 15 etc. seems like overkill. ...

Multiple groups in LinqToSql

I dont seem to be able to find any evidence of multiple groupby being supported in LinqToSQl on the internet (I should probably buy a book :)) I'd like to be able to do this: var qry = from s in DBContext.Styles join artist in DBContext.Artists on s.ID equals artist.StyleID join track in DBContext.Tr...

Linqtosql sync with the database

Hi All, I am about to use linqtosql in my first asp.net mvc application. I have come up with a database schema. But the problem is that I may change few of the tables in future. So keeping the model classes in sync with database will be a issue. I got this link which states the similar situation, http://stackoverflow.com/questions/91...

Linq to Sql, Many to Many and Interfaces

I am using Linq to Sql to access my SQL Server Database. The database contains some tables that have many to many relationships between them which leads to an awkward syntax in the Linq generated classes where I have to create a link object and associate it with both tables (child and parent), rather than just adding the child to a colle...

LINQ to SQL - need downloading sqlserver 2008 to a local mdf file

i have a sql server that i use and i am trying to code up a solution using LINQ to SQl in visual studio. is there a way i can: download the database from my server to my local desktop and have it as a mdf file so i can bring it into the app_data folder and it use this for LINQ to SQL code generation. also, please let me know if there ...

Why is my LINQ DataClass Context Object not showing up?

Here is an image of my project's tree view: As you can see, My linq data object resides in the App_Code folder under 'FYI'. When I open the ControlPanel.ascx and add the LinqDataSource object, then go to select the context object this is what I see: I am baffled as to why it is not showing up. Does anyone know why this might be ha...

How would you code a repository pattern like a "factory" design pattern?

I thought I would rewrite this question (same iteration). The original was how to wrap a repository pattern around an EAV/CR database. I am trying a different approach. Question: How could you code a data repository in a "factory" design pattern way? I have a fixed number of entities, but the attributes to these entities are fairly c...

Which Repository do I put my SelectList in?

If I have an Invoice Line Items table and a Products table, and I have a dropdown in my invoice line items to select a product, I will need a SelectList to populate the dropdown with product names. Which repository do I put the product SelectList method in, the Invoice Line Items repository or the Products Repository? To me it makes ...