linq-to-sql

Serialize Linq objects not working

Using the following code: Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer = From c In db.Customers Select c Dim dcs As New DataContractSerializer(GetType(Customer)) Dim sb As StringBuilder = New StringBuilder Dim writer As XmlWriter = XmlWriter.Create(sb) dcs.Writ...

linq2sql: singleton or using, best practices

what is the preferred practice when linq2sql using (in asp.net mvc applications): to create "singleton" for DataContext like: partial class db { static db _db = new db(global::data.Properties.Settings.Default.nanocrmConnectionString, new AttributeMappingSource()); public static db GetInstance() { return _db; } }...

ASP.NET MVC 2 + LINQ to SQL - CS0012 Compilation Error

Hi, In my database schema each forum has a category and categories can have many forums. I'm trying to list categories and their respective forums with the following code: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <asp:Content ID="Content1" ContentPlaceH...

Order by descending based on condition

Hello All, I want to write a LINQ to Entity query which does order by ascending or descending based on input parameter, Is there any way for that. Following is the my code. Please suggest. public List<Hosters_HostingProviderDetail> GetPendingApproval(SortOrder sortOrder) { List<Hosters_HostingProviderDetail> returnList ...

How to transform vertical table into horizontal table?

Hello, I have one table Person: Id Name 1 Person1 2 Person2 3 Person3 And I have its child table Profile: Id PersonId FieldName Value 1 1 Firstname Alex 2 1 Lastname Balmer 3 1 Email [email protected] 4 1 Phone +1 2 30004000 And I want to get data from these two tables in one row ...

oData/ADO.NET Data Services using LINQ-to-SQL with a decryption layer

I have written an application using LINQ-to-SQL that submits a web form into a database. I absact the LINQ-to-SQL away using a Repository pattern. This repository has the basic methods: Get(), Save(), etc. As a development of the project, I needed to encrypt certain fields in the form. This was trivial, as I just added the encryption c...

using indexer to retrieve Linq to SQL object from datastore

class UserDatastore : IUserDatastore { ... public IUser this[Guid userId] { get { User user = (from u in _dataContext.Users where u.Id == userId select u).FirstOrDefault(); return user; } } ... } One of the d...

Can I serialize an object if I didn't write the class used to instantiate that object?

Hello, I've a simple class [Serializable] public class MyClass { public String FirstName { get; set: } public String LastName { get; set: } //Bellow is what I would like to do //But, it's not working //I get an exception ContactDataContext db = new ContactDataContext(); public void Save() { Contact contact = new Co...

Linq to SQL :How to work with already existing Business objects(Handwritten)

I was trying to implement a LINQ 2 SQL implementation to one of my page to load the data to a datagrid.The below is the code using (NorthwindDataContext context = new NorthwindDataContext()) { var customers =from c in context.Customers select c; // Line 1 gridViewCustomers.DataSource = customers; gridViewCustomers.DataBind();...

convert sql to linq sample

Hello, I've got a sql statement, but I can't get it working in linq. Can someone show me how I can write the following sql statement as linq? SELECT * FROM mobileApplication LEFT JOIN videoMobile ON mobileApplication.id = videoMobile.mobileApplicationId AND videoMobile.videoId = 257 It's a left join with a where statement on th...

Fill WinForms DataGridView From Anonymous Linq Query

// From my form BindingSource bs = new BindingSource(); private void fillStudentGrid() { bs.DataSource = Admin.GetStudents(); dgViewStudents.DataSource = bs; } // From the Admin class public static List<Student> GetStudents() { DojoDBDataContext conn = new DojoDBDataContext(); var query = (from s in conn....

What the heck is happening with this Linq-to-SQL query?

[Resolved - see update] I have this L2S query (looks scary, but the bit that's going wrong is simple): var historicDataPointValues = from dpv in this._dataContext.DataPointValues where (dpv.categoryId == historicCategoryId) && (dpv.retailerId == historicRetailerId) ...

"Cleanly" Deploying an ASP.NET Application with LINQ to SQL Server

In my development environment, my SQL Server is PHILIP\SQLEXPRESS. In testing, it's ANNIE, and the live environment will have a third name yet to be determined. I would have assumed that updating the following statement in web.config would have been enough: <add name="MyConnectionString"providerName="System.Data.SqlClient" connectionSt...

LINQtoSQL Custom Constructor off Partial Class?

Hi all, I read this question here: http://stackoverflow.com/questions/82409/is-there-a-way-to-override-the-empty-constructor-in-a-class-generated-by-linqtosq Typically my constructor would look like: public User(String username, String password, String email, DateTime birthday, Char gender) { this.Id = Guid.NewGuid(); ...

Best way to get record counts grouped by month, adjusted for time zone, using SQL or LINQ to SQL

I'm looking for the most efficient way to suck out a series of monthly counts of records in my database, but adjusting for time zone, since the times are actually stored as UTC. I would like my result set to be a series of objects that include month, year and count. I have LINQ to SQL objects that looks something like this: public clas...

Processing a property in linq to sql

Hi It's my first LINQ TO SQL Project , So definitely my question could be naive . Till now I used to create new property in Business Object beside of every DateTime Property , That's because i need to do some processing in my DateTime property and show it in special string format for binding to UI Controls .Like : private DateTim...

Inserting Multiple Records in SQL2000

I have a web app that currently is inserting x (between 1 + 40) records into a table that contains about 5 fields, via a linq-2-sql-stored procedure in a loop. Would it be better to manually write the SQL Inserts to say a string builder and run them against the database when the loops completed rather than 30 transactions? or should I j...

LINQ to SQL: Reusable expression for property?

Pardon me for being unable to phrase the title more exact. Basically, I have three LINQ objects linked to tables. One is Product, the other is Company and the last is a mapping table Mapping to store what Company sells which products and by which ID this Company refers to this Product. I am now retrieving a list of products as follows:...

How do I improve the efficiency of the queries executed by this generic Linq-to-SQL data access class?

Hi all, I have a class which provides generic access to LINQ to SQL entities, for example: class LinqProvider<T> //where T is a L2S entity class { DataContext context; public virtual IEnumerable<T> GetAll() { return context.GetTable<T>(); } public virtual T Single(Func<T, bool> condition) { ret...

How to write back to database from Silverlight?

Hi, I use LINQ to SQL to get data from a database and use a service contract to access it in Silverlight at the client side. I display the data in a DataGrid. Now how do I make sure that any changes in the datagrid is written back to the database? EDIT: This is the example code I implemented: http://www.silverlight.net/learn/tutorials...