linq-to-sql

MVC Dropdownlists - How to Set Dummy Values

This is kind of a two parter: 1) Where should I be feeding my DDL's from? Right now I have List set in my viewmodel. I've seen a lot of people set the lists in the ViewData[]. Is that what I should be doing, and why? I've noticed that the DDL values are not retained in the HttpPost and I have to reset them in the view model. If I u...

LINQ to SQL on Dynamic Entity Types?

Trying out a new project with Framework 4.0. I have 2 SQL Server tables with matching DBML entities in my project (EntA and EntB). EntA has a Notes property that maps to a VarChar(50) column. EntB has a NoteText property that maps to a Char(100) column. I have some simple Linq-to-SQL code that prepends the text "* Note: " for each e...

Using Linq-to-SQL preload without joins

Like many people, I am trying to squeeze the best performance out of my app while keeping the code simple and readable as possible. I am using Linq-to-SQL and am really trying to keep my data layer as declarative as possible. I operate on the assumption that SQL calls are the most expensive operations. Thus, I try to minimize them in qu...

LINQ InvalidOperationException when making a query

Ok, last edit, promise: With the following class: public partial class MembershipModule : BaseConnection<MembershipModule> { private const string AccessPrivilege = "Access"; public bool Accessible() { return this.Privileges().Any(p => p.Name.Equals(AccessPrivilege)); } public IQueryable<MembershipAction> P...

LINQ2SQL LIKE Command for Phrase

Hi all, I am trying to retrieve a list of string where it contains "Britney Spears", and this is what I use from p in Objects where p.Title.Contains("Britney Spears") select p That works fine, but if I want to select title which is "Britney Jean Spears", "Britney 'Sexy' Spears" it doesn't work, so my question is how do I insert a wil...

Very slow insert process using Linq to Sql

I'm inserting large number of records using LinqToSql from C# to SqlServer 2008 express DB. It looks like the insertion is very slow in this. Following is the code snippet. public void InsertData(int id) { MyDataContext dc = new MyDataContext(); List<Item> result = GetItems(id); foreach (var item in result) { DbItem dbIte...

Linq-To-Sql Method Not Supported?

I'm using a query that tries to find a matching unique identifier (guid) such as var myUsers = from u in table where u.UniqueIdentifierId == MyClass.GetCurrentUserId() select u; This throws the Method Not Supported error for my custom function. I recoded it to do this string guid = MyClass.GetCurrentUserId...

Dynamic Search multiple terms in linqtosql

I'm trying to do the following, If a user the enters the term "IP Address Text" into my search box then I want the following SQL to be generated: SELECT * FROM tblComments WHERE tblComments.Text LIKE '%IP%' OR tblComments.Text LIKE '%Address%' OR tblComments.Text LIKE '%Text%' Obviously the number of words entered is going to be diffe...

Why my LINQ expression do not work in LINQ to SQL?

private System.Linq.Expressions.Expression<Func<ActionLogs, bool>> GetExpression() { Expression<Func<ActionLogs, bool>> expr = w => w.ID != -1; if (ActionDate != null) { Expression<Func<ActionLogs, bool>> byDate = w => w.DateAction == ActionDate; var body = Expression.AndAlso(expr.Body, byDate.Body); e...

Linq GetTable< > return empty rows

I have a very strange problem. I followed an MVC tutorial. I have an interface: namespace DomainModel.Abstract { public interface IProductsRepository { IQueryable<Product> Products { get; } } } A repository inherits that interface: namespace DomainModel.Concrete { public class SqlProductsRepository : IProduc...

How to get all Types using LINQ in Asp.net mvc

Hello Friends, I have this code viewModel.Messages = repository.GetAllMessages().OrderBy(x => x.MessageText); with this I am getting 75 messges and i am displaying all the Messages in the Grid with two columns MessageText and MessageType But I need to write a Linq Query to get all my Distinct MessageTypes from Messages? Can any ...

Convert the Following Lines

How can i convert the following lines so that i can get the selected data from a combo box in a WPF Datagrid. The combo box is bound to a Linq to SQL table. object obj = ((DataRowView)editingElement.DataContext).Row [this.SelectedValuePath]; and (DataRowView)editingElement.DataC...

Can anyone modify this LINQ to SQL query so it only returns one instance of each row?

var nodes = (from n in db.Nodes join st in db.SessionTrackings on n.NodeID equals st.NodeID where st.UserID == userid && st.GroupID == groupid select n); IDictionary<int, bool> trackingData = new Dictionary<int, bool>(); foreach (Node n in nodes) { trackingData.Add(new KeyValuePair...

The constant for Guid is not supported

Using SubSonic and linq-to-sql, I want to join two tables, but under a little bit different circumstances, based on runtime conditions. The tables are PriceListItem and CatalogItem. I have defined a struct, JoinedItem, that has one member for a data object from each table. struct JoinedItem { public PriceListItem pli; ...

Is it possible to have auto filters in Linq to SQL ?

Hi ! I am working on a system that the client decided to use status for the records. One of them is X for excluded. What I want to know is if it is possible to run linq queries that adds something like where status != 'X' Automatically to not show "excluded" records. Thanks ! ...

Removing non-unique data on insert

Table entity column is unique, and I'm trying to add items. Items amount is fairly big, so i'm trying to avoid connecting to a database many times. What is the best way to ignore duplicates? Example: code Edit: Problem was word1 was of type nchar(50), so after changing it to nvarchar(50) everything worked. ...

Get Linq to SQL to save to the database

So I have the following code: // Get the current user _currentUser = WindowsIdentity.GetCurrent(); // Get the list of address for the current user _dataMap = new DataMapDataContext(); _addresses = _dataMap.Addresses .Where(address => address.InsertUserName == _currentUser.Name).ToList(); .... _addresses.Add(form.Item); _dat...

How can i get next ident ID before submit in Linq-to-sql

I mean i want to get next ID, which is identity, log it somewhere and only then do SubmitChanges() ...

Developing a data access layer using ADO.Net and LINQ

I have a potential project where I would be working on developing the "Data Access Layer" of a reporting application using ADO.Net and LINQToSQL. I have not specifically worked on a Data Access Layer project (middle tier), so I was wondering if anyone here could provide a sample / example / resource, where I can get an idea of what th...

Caching for poll?

I'm building a poll widget using ASP.NET controls and Linq-to-Sql for a high traffic site. The widget is, actually, already built. But, it does not use caching yet. This poll can work in a multi-poll mode which means that each page load the control will hit the database to find any polls that the current user has not taken. There are al...