linq-to-sql

Setting Connection string in dbml files using Linq to SQL in Visual Studio 2008

I have an application that works with a database "TestDB". At the time I was developing the application I was using linq to sql and adding my data tables by dragging and dropping to the TestDB.dbml file and probably .net automatically sets the connection string to the local sql server on my machine. The application is supposed to launch ...

Do we have to use GUIDs in LinqToSql application to uniquely identify objects

I have inherited a LinqToSql application which is making use of GUID keys for objects. I'd rather use conventional identity fields - much easier for people to use, understand and communicate. However there is some business logic that requires the application to identify unique objects before they're persisted to the DB which is why GUID...

Linq to SQL: Group By and Sum()

I'm very new to linq so this should be pretty easy to answer, but I've had a hard time finding the answer. I have the following LINQ statement, which performs a simple linq query and assigns the resulting values labels on an asp.net web form: Dim db As New MeetingManagerDataContext Dim q = From s In db.vwRoomAvailabilities ...

Help adding properties to LinqToSql classes

I need to define these two Properties to one of my linqclasses (Employee).. because I need to keep track of the health progress of Employees... Each employee takes monthly PhysicalExams so I defined these properties public decimal? Initial_Mass_Index { get { return this...

Remove Duplicate based on column value-linq

Hi i have many to many relationship between employee and group. following linq statement int[] GroupIDs = {6,7}; var result = from g in umGroups join empGroup in umEmployeeGroups on g.GroupID equals empGroup.GroupID where GroupIDs.Contains(g.GroupID) select new { GrpId = g.GroupID,EmployeeID = empGr...

How can I use two different data contexts in one LINQ request?

Hi all, Can anybody help me with next: how can I use two different data contexts in one LINQ request? using (var db = new DataMapDataContext(Connection)) { using (var dbAdd = new DataMapDataContext(ConnectionAdd)) { return (from i in dbAdd.ITEMs join p in db.U_...

ScriptIgnore in Linq-to-SQL

I have a Linq-to-SQL entity that I will be serializing and returning as JSON over a webservice call. There is one property on that entity that I would like not to be serialized. For this, there is generally the [ScriptIgnore] attribute, which works exactly the way I want if I manually add that to the designer.cs file. Now, since the de...

link for repository implementation in linq to sql

Can someone please tell me few link where "implementing repository pattern in linq to sql" is explained better. ...

LINQ to SQL - To Use or Not To Use that is the Question.

I come from a different language and there are always the different views about what to use and what not to use. What is your opinion and pros and cons on why to use or not use LINQ to SQL? Also I saw there was a LINQ to NHibernate is this worth using if you have NHibernate? I have not gotten NHibernate installed just yet. Thanks ...

Caching linq-to-sql results?

Most will recommend caching as a list. I know that is a solution and may be the one I go with. But, what if one wants to be able to treat a cached linq-to-sql with full IQueryable (IEnumerable?) functionality? If one does try to cache the raw result, an error "Query results cannot be enumerated more then once". So, to make clear my que...

using a static DataContext in a WCF Service causing errors?

I have a WCF Service that maintains several connections to various databases. I am using Linq to Sql Objects. The approach I have taken is that I have a list of available connections in a database, and when I call the service I see if a DataContext already exists, and if not I create a new DataContext private static Dictionary<String,...

Can a class derived from a Linq to SQL entity still be saved?

Hi, Say "Foo" is a Linq to SQL entity created in the Linq to SQL designer. I then have "Bar" which derives from "Foo". Should I be able to save "Bar" using Linq to SQL (assuming I don't care abut saving any of the extra properties on Bar). using (myDataContext ctx = new myDataContext()) { ctx.Foos.InsertOn...

LINQ to SQL distinct records

I want to get distinct records by using LINQ not on the base of Id but on other field of the table i.e. date. The table schema is ID (Unique Identifier),date (dateTime), Desc varachar(50) Records are like : 1st row: Id 61DDF6A2-E5B7-4E88-91FE-5C63EF8E15D8 date 8/1/2010 Desc Abc 1st row: Id 61DDF6A2-E5B7-4E88-91FE-5C63EF8E15D8 date 8/1/...

IEnumerable vs list

is this is proper use of IEnumerable or shell i use list? what i need to put in <PropertyInfo>? public static IEnumerable<PropertyInfo> GetNewsList<T>(int FID) { CatomWebNetDataContext pg = (CatomWebNetDataContext)db.GetDb(); return (from nls in pg.NewsCat_ITEMs join vi in pg.VIRTUAL_ITEMs on nls.NC...

How can i shorter my linq codes?

hi; i try to run my codes. My program more slowly runnig. i need to give performance also write less codes in GetAliSpReqs(), GetMaintData();GetAccess....GET(... How can i write more effective below codes. They are too slow also not useful. forexample i try to write les than 1-2 line with GetAliSpReqs()? How can i ? please help me... ...

SQL Linq Question

I have the following working TSQL query in ms SQL 2008 SELECT Date, COUNT(click) AS clicks, COUNT(sale) AS sales, count(lead) as leads FROM ( SELECT ClickDate as date ,ID AS click ,CAST(NULL AS int) AS sale , CAST(null as int) as lead FROM clicks UNION ALL SELECT Date,null, ID ,NULL FROM sales UNION ALL SELECT Date,...

writing t-sql version of .net codes by using sqlclr

hi, i have a lot of methods wrote with.net codes (c#) to using with linq queries. but i have problem to translating methods to t-sql. and i want to convert that to t-sql functions and using that with t-sql queries directly. how? ...

Abstract class in LINQ2SQL for sharing common methods

Hi, I'm having trouble trying to implement a shared method/property between two classes created by the linq2sql designer. My two classes have two main properties (coming from the db model): public partial class DirectorPoll { public bool Completed {get; set;} public bool? Reopen { get; set; } //more properties } public par...

in C#.net, Can i pass a DataContext object (created by LINQ to SQL) as a parameter of a method in another class ?

in C#.net, Can i pass a DataContext object (created by LINQ to SQL) as a parameter of a method in another class ? ...

LINQ to SQL INSERT WHERE not in collection

I need to mirror all of the DNS entries on our DNS server in a SQL database. I am able to query DNS using WMI and C#. And I can query SQL for existing records using L2S but there is a lot of room for improvement. What does the LINQ To SQL statement look like that will insert records that are not in the ManagementObjectCollection returne...