I have an array of integers in string form:
var arr = new string[] { "1", "2", "3", "4" };
I need to an array of 'real' integers to push it further:
void Foo(int[] arr) { .. }
I tried to cast int and it of course failed:
Foo(arr.Cast<int>.ToArray());
I can do next:
var list = new List<int>(arr.Length);
arr.ForEach(i => list.Add...
I have a LINQ query to retrieve the maximum value of an integer column. The column is defined as NOT NULL in the database. However, when using the MAX aggregate function in SQL you will get a NULL result if no rows are returned by the query.
Here is a sample LINQ query I am using against the Northwind database to demonstrate what I am d...
Hi,
I have the folowing SQL query:
Select *
from aspnet_Users
where UserId Not in
(select UN.ConnectedToUserID
from tblUserNetwork UN )
and UserId <> '82522f05-2650-466a-a430-72e6c9fb68b7'
What will be the LINQ equivalent to this SQL.
Thanks
...
I'm using LINQ to model my database, but I'm writing it by hand (Steve Sanderson recommends this in his ASP.NET MVC book). What I need to know is what's happening when you create an EntityRef, and how it's referenced. If I create my queries manually (without using LINQ), but use LINQ to model it, and I bring back just the ID of somethi...
I have two List<T> objects:
For example:
List 1:
ID, Value where Id is populated and value is blank and it contains say IDs from 1 to 10.
1,""
2,""
...
10,""
List 2:
ID, Value and other attributes all filled with values but this list is a subset of List 1 in terms of IDs. (e.g only 3 items)
2,67
4,90
5,98
What I want is a merged li...
Database example:
Image - ImageTag - Tag
Images can have multiple tags. The relationships are set up fine and stuff but I am running into performance issues.
I have many different queries which select Images according to different criteria. They work fine, however the data for the Tags are not selected with these queries.
This means ...
Here is what i have:
a SQL CE database, that holds this Category table, with id and name columns only.
dbml generated with sqlmetal
singleton (static class) that exposes the linq DataContext.
in the code-behind file, i have a property like follows:
private System.Data.Linq.Table Categories
{
get
{
return LibraryDataSt...
Hello, I'm having troubles with the Except() method.
Instead returning the difference, it returns the original set.
I've tried by implementing the IEquatable and IEqualityComparer in the Account.
I've also tried creating a seperate IEqualityComparer class for Account.
When the Except() method is called from main, it doesn't seem to ca...
So here is the scenario: i have a series of different repository classes that each can use an isolated data context, or a shared context. In the cases where an isolated context is being used i want to add a method to the base class that will allow me to specify the lambda as the parameter, have that expression be executed by the isolated...
I have a class MyClass with a method:
public bool MyMethod(out DateTime? MyDate) {
...
}
I'd like to call this method in the following way:
var q = from mc in MyClasses.AsEnumerable()
from output in mc.MyMethod(out dt) // how to declare dt?
select new { mc, output, dt };
Obviously this doesn't compile, coz I haven...
Hi,
I have a table named tblUserNetwork. It contains composite primary key on UserID and ConnectedToUserID
When i update the table networks.Update(networks), it gives error like this:
Table dbo.tblUserNetwork contains a composite primary key field
What is the problem in updating.
I am updating many other table they don't have comp...
I've seen it said in other questions that the Linq query syntax compiles to a Lambda.
So why can you not do edit-and-continue when there is a Lambda expression in the method, while with query notation you can?
What's most infuriating, and is seriously making me consider switching to using query notation everywhere, is that even if your...
I dont't know how to describe the title better (so feel free to change) but essntial I want to produce the equivilent of the following statement in LINQ to SQL:
select * from products where category in ('shoes','boots')
The fields will be coming from the query string essentially (more secure than this but for ease of explanation) i.e
...
I am trying to build a LINQ query at runtime so that only certain properties are selected. I have thought of something along the lines of being able to build a query by appending additional .Select() calls to my query or using the dynamic LINQ extensions to pass a string of columns (would like to stay away from a string built query). H...
When working with Windows Form controls and LINQ is there a "Best Option" for how your Buisiness Layer returns the Data?
Right now I am returning DataTables so that I can then set the DataSource to the returned DataTable. Is there a better option? Why?
public class BLLMatrix
{
public static DataTable GetMaintItems(int iCat)
{...
Hello all,
I am using c# .net.
aspx form
<asp:Table ID="viewV" runat="server">
<asp:TableRow>
<asp:TableHeaderCell>Name</asp:TableHeaderCell>
<asp:TableHeaderCell>Type</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
Code Behind
vRepository getV = new vRepository();
var viewAllV = getV....
This one seems like it should be pretty straightforward, but I couldn't quite figure it out or find anything on it.
My query looks something like this:
from o in objects
select new
{
o.ID,
o.member.Number,
o.member.Date,
o.member.total,
o.SequenceNumber,
...
I am playing with MVC and I made a simple site. I have an seperate machine running SQL Server Express and on it I have a simple table called "Log". The table has ID, Timestamp, and Message fields. I added the database to my "Data Connections" on my "Server Explorer" section.
In my MVC website I created a new LINQ to SQL class and dragge...
We're getting an error when deploying a project to one of our client's servers. The system works fine in our local dev and staging environments. The error is:
The type or namespace name 'Linq' does not exist in the namespace 'System.Data'
We've done the obvious checks:
- We have the references in the web.config for System.Data.Linq...
I'd like pick out a List the items 5 - 10 and create a new list of the same type.
Using Linq I thought of:
List<xyz> collection = new <List>();
//fill collection with lots of data
collection.AddRange( ... );
//Downsize here
var q = from e in collection select e;
q.ToArray();
List<xyz> smallcollection = new List<xyz>()
smallcollection =...