linq-to-sql

Linq to Sql method return type

I have a stored procedure that has FOR XML AUTO and I use it in a dbml file. The problem is that I want the return type to be XDocument. For now it returns the xml string cut into pieces. I can use someting like : foreach(spMyProcedure_GetResult getResult in list) { sb.Append(getResult.XML_F52E2B61_18A1_11d1_B105_00805F49916B); }...

Speeding up code that copies database structure to XML

I have a database structure filled with data that I'm trying to write out to an XML file. Here's a taste of the way the VB code is structured: Dim xsi = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance") Return _ New XElement( _ "providers", _ New XAttribute(XNamespace.Xmlns + "xsi", xsi.NamespaceName), _ ...

Need help with LINQ to SQL WHERE-clause on foreign table

Let's say I have these two tables: ParentDataItem ParentDataItemID ...some other fields... ChildDataItem ChildDataItemID ParentDataItemID (foreign key) Name Value Now I want to select any ParentDataItems that have a ChildDataItem with a specified name and value. I know I was way off with my first approach, wh...

difference between linq to sql and entity framework

Hi fnds, There are lof of difference between Linq to Sql and Entity framework like Linq to SQL is one to one mapping and EF is many to many mapping and many other which can be found at http://stackoverflow.com/questions/8676/entity-framework-vs-linq-to-sql But here I am asking with EF and Linq to Sql, do we create Entities first and th...

Left joins in LINQ to SQL

This is my query: Dim bugs = (From b In bugCon.bugs Where sctUserIds.Contains(b.Developer.Value) Order By b.bg_id Select Bug = b, Project = b.project).ToList Currently this does an inner join between "bugs" and "projects". How do I turn it into a left join? ...

LINQ to SQL - No Foreign Keys

No foreign keys defined in the database. So I've setup associations. problem: can't seem to be able to reference the Role table as expected: I can get as far as u.UserNamesInRole then can't make the jump to role table. IEnumerable<fmwebapp1.Old_App_Code.TelerikUsersDataContext.User> userList = (from u in dbTelerik.Users where u.Us...

The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[Models.MailListViewModel]'

Hi, I am getting an error saying: The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[WebUI.Models.MailListViewModel]', but this dictionary requires a model item of type 'WebUI.Models.MailListViewModel'. This is in my controller: public ViewResult List() { var mailToShow = from m in mailReposito...

LINQ to SQL filter by List<int>

Hello, How can I retreive rows from table only when UserId is in my Users list ? Code below doesnt work :/ List<int> selectedSourceUsers = ... MyModelDataContext context = ... e.Result = from u in context.Users from id in selectedSourceUsers where u.UserId == id select u; Tha...

Update only part of a Model, validation problem?

Hi, I have a sign-up page where the user can input his FirstName, LastName, Email and Password, along with other fields. I have bound validation attributes to this Model (called "User" and created via LINQtoSQL) and all works well. Model code: [MetadataType(typeof(UserValidation))] public partial class User { } [Bind(Exclude = "User...

Problem accessing association from the result of a lambda query

Has anyone had problems gettting associations to load using LINQ to SQL when your child record was loaded via a lambda query? For example: var orderLine = db.OrderLines. Where(ol => ol.ID == orderLineID select ol). First(); // navigate to order via the association var order = orderLine.GetOrder(); What I get basically is a nul...

Project generic type into a KeyValuePair

I'm sure what I'm trying to do is fairly simple but I'm struggling. I simply want to project an IQueryable into a key value pair. This is part of my class: public DropDownListActionResult(IQueryable<T> dataItems, Func<T, int> keySelector, Func<T, string> valueSelector, int? selectedID) { _dataItems = dataItems; _keySelector = ...

List, IList, IEnumerable, IQueryable, ICollection, which is most flexible return type?

I've seen this question posted here previously but I'm not satisfied that I understand the complete ramifications. The problem is what return type should a data layer that uses linq-to-sql return for maximum flexibility and query ability. This is what I've read/found: IEnumerable is limited and only allows for read forward operation. I...

How do I connect my Silverlight app to a WCF Service?

I've been looking for this answer, and all I found was this link, but when I attempted to follow the tutorial I failed hard. What I need is to connect my Silverlight application to a database, just to show informations from a specific table. As I don't want to use the same ORM for my page and my silverlight app, I created a new WCF webse...

Filter a list of objects by comparing with another list of different objects

I have the following 3 classes in my dbml file: public class Player { public int PlayerID {get; set;} public string Name {get; set;} } public class PlayerItem { public int PlayerItemID {get; set;} public int PlayerID {get; set;} public int ItemID {get; set;} } There is an association created between Player.ID and...

Controlling DBML EntityRef creation in DBML with multiple foreign keys

Using Linq to SQL and the autogeneration capabilities of DBML, foreign key relationships create EntityRefs in the DBML designer file. For example : private int _USStateId; private EntityRef<USState> _USState; However, if I have the need for a table with numerous FK relationships to the same table, how can i control the autogenerated...

Linq2Sql not updating NVarchar(Max) field?

I have the folowing code to fetch a record and update one column which is of type NVarchar(Max) using Linq2Sql. using (var context = new DataClasses1DataContext()) { var entity = context.Entity.Where(d => d.ID == 12).Single(); entity.EmailTemplate = "Test Template"; context.Sub...

LINQ to SQL DAL, is this thread safe?

My code is written with C# and the data layer is using LINQ to SQL that fill/load detached object classes. I have recently changed the code to work with multi threads and i'm pretty sure my DAL isn't thread safe. Can you tell me if PopCall() and Count() are thread safe and if not how do i fix them? public class DAL { //read one Ca...

.Net - accessing multiple sql server groups / databases

My program (WCF service programming in C#) has to access multiple sql server groups and the databases within those groups (sql server). It looks like linq 2 sql definitely doesn't support this unless I create multiple dataclasses per database, and it looks like the entity framework is in the same boat. How would you go about setting up ...

.Net - accessing multiple sql server groups / databases

My program (WCF service programed in C#) has to access multiple sql server groups and the databases within those groups (sql server). It looks like linq 2 sql definitely doesn't support this unless I create multiple dataclasses per database, and it looks like the entity framework is in the same boat. How would you go about setting up yo...

How to use linq-to-sql group by to list duplicated records?

Suppose I have two tables: Category and Product. I want use linq-to-sql to select all categories (with products) that have duplicated products. My query goes like this: from p in db.Products group p by p.CategoryId into c select new { categoryId = c.Key, products = from PbyC in c group PbyC by PbyC.Name into dupl where dupl.Count(...