I want to select all questions from the questions table that haven't been included already for a particular quiz.
My question is why does the below code fail with the message :
The text data type cannot be selected as DISTINCT because it is not comparable.
The data types text and text are incompatible in the is operator.
var allQuestio...
Is there any way in LINQ to do an OrderBy and then do a ThenBy with the ThenBy using the children of the parent object to do the secondary ordering?
_repository.GetActiveDepartmentGroupsWithDepartments().OrderBy(c => c.DepartmentGroupName).ThenBy(c => c.Departments.OrderBy(d => d.DepartmentName))
In the above case, c.Departments is an...
Hi ,
I have a post class :
class Post
{
public int ID;
public int? ParentID;
}
The only difference between answer and question in post class is that question has parend id equals null.
And I want to write one query which always return question and it's answers no matter i pass to it ID of question or ID of answer
for example:
I h...
In one of my previous questions about using dynamically built up strings (where clauses) and using them in LINQ, I was guided towards the LINQ Dynamic Query Library Dynamic LINQ.
The first issue was that it only applies to IQueryable, this however can be overcome by using the .AsQueryable() extension method on any IEnumerable.
The prob...
I have following LINQ to SQL query
from msg in TblUserMessages
join user in Aspnet_Users on msg.FromUserID equals user.UserId
select new {
msg.FromUserID,
msg.ToUserID,
msg.MessageLocationID,
msg.MessageID,
user.UserName
}
And following lambda expression:
TblUserMessages
.Join (
Aspne...
Hello,
I am using a FormView control to edit a record fetched using a LinqDataSource. In essence, the markup for the FormView and the data source looks like this:
<asp:FormView ID="RuleInstancePropertiesFormView" runat="server" DataKeyNames="RuleInstanceId"
DataSourceID="RuleInstanceDataSource" DefaultMode="Edit" Visible="false"
CssCla...
Can someone help me translate this query to LINQ? I cant find a good way to translate it, Thanks!
SELECT
C.id,
C.id_old,
C.cus_id,
C.namefirst,
C.title,
CP.id as 'cus_phone_jct.id',
CP.contact_id,
CP.phone_id,
CP.ext,
P.id as 'cus_phone.id',
P.phone,
P.typ_id,
P.status_id,
P.donotcontact
FROM cus_contact C...
Ok, this has been a head scratcher for me. I have a ListBox I am binding to a linq query like so:
private IQueryable<Feed> _feeds;
public IQueryable<Feed> Feeds
{
get
{
if (_feeds == null)
{
var feedsQuery = from f in _db.Feed orderby f.Title select f;
...
I have a many to many table relation ship:
CUS_Phone: holds its own unique id, the cus id from its parent table as well as name title dates, etc...
CUS_Phone_JCT: Holds its own unique id, the id from the CUS_Phone and the id from CUS_Phone
CUS_Phone: Holds its own unique id, and the phone number
Here I have a join query to retrieve al...
I have been pondering for a while how to best cache IQueryables. I am using a repository pattern to fetch data into a class such as this one:
public class Item
{
public int Id { get; set; }
public string Name { get; set; }
public IQueryable<Category> { get; set; } // For simplicity. It is actually a LazyList<Category> contai...
I have this function that shows a list of messages in reverse order.
protected void setupMessages(IList<Message> Messages)
{
List<Message> messages = new List<Message>() ;
messages.AddRange( Messages.OrderBy(message => message.DateAdded).Reverse());
MessagesRepeater.DataSource = messages;
MessagesRepeater.DataBind(...
Should I bother doing this check to see if the object(s) saved correctly?
if (objectContext.SaveChanges() > 0)
It should just throw an exception if it didn't, right?
...
Suppose I have an IQueryable<T> expression that I'd like to encapsulate the definition of, store it and reuse it or embed it in a larger query later. For example:
IQueryable<Foo> myQuery =
from foo in blah.Foos
where foo.Bar == bar
select foo;
Now I believe that I can just keep that myQuery object around and use it like I describe...
I have the code below in an attempt to allow the user to "Step Through" the Case Notes in the DB by clicking Next or Previous on the WinForm. It will grab the First Case Note only.
What am I doing wrong?
There has been numerous edits to this post, I apologize, but in following Jon Skeet's advice I was able to "fix" what was originally ...
If I wanted to badly enough, could I add additional LINQ constructs to LINQ-to-SQL (as I would be able to if creating my own LINQ provider)? For instance, many of the built-in LINQ operators (XYZ.Any()) get directly translated to SQL (e.g. IF EXISTS(XYZ) ).
If I needed a specialized construct, would I even be able to augment the set, o...
I am using the version 1.0 release of Linq for nHibernate. When I run
the following linq statements I receive the error
not a single-length projection: Surname
I can find very few references to this on the web and looking into the
source it says it should never occur! ClientID is a Int type and
Surname is a string. When I comment out a...
Here's the code in question:
parentNodes.AsParallel().ForAll(parent =>
{
List<Piece> plist = parent.Field.GetValidOrientations(pieceQueue[parent.Level]);
plist.ForEach(p =>
{
TreeNode child = new TreeNode(p, parent);
var sco...
Example: I have an in-memory list of customers. Every customer has a list of orders. Every order has a list of items. Every item has an item-code.
I need to get a list of items grouped by the itemcode, with beneath it the customers who have ordered this item. If a customer ordered an item twice or more, he should still be shown as a sin...
I'm using LINQ to build up a tree structure of objects from a collection of objects which were retrieved from a stored procedure call.
I want to know if
a) there is any way to remove elements from one collection to a new collection
b) if there is actually any point performance wise in doing this
my code looks something like this:
cla...
I'm trying to use Linq to run queries against a linked server on our SQL Server machine through Visual Studio.
On the SQL Server, I've successfully created the linked server and can run queries on it. In Visual Studio I've added a new data connection (under Server Explorer) to the SQL Server with success but the linked server tables are...