The following code is causing a "This query contains references to items defined on a different data context" error. My 2 data contexts are created with 2 nested using blocks around the code that calls this method and displays its results on screen. The methods that this method calls only use the data context passed in to them, they don'...
As an example, say I have an array of names and I want to create an array of Person objects by calling a constructor that takes string name.
class Person()
{
public string Name { get; set; }
public Person(string name)
{
Name = name;
}
}
...
static void Main()
{
string[] names = {"Peter", "Paul", "Mary"};
...
When I read code that uses Select I think "select-all-where".
When I read code that uses Map I think "this-to-that" or "apply-to-all".
I can't be the only person that feels the name Select is confusing.
Map
...
i have a objectA
public class objectA
{
public int Id;
public string Name;
}
i have a list of objectA
List<objectA> list;
i want to find in the list any objectA with Id = 10;
is there linq syntax for this or do i simply have to write a loop here.
...
Hi,
Not sure if I'm missing anything here. Basically, I am looking for Linq to Nhibernate to do the following SQL statement:
update SomeTable
set SomeInteger = (SomeInteger + 1)
where SomeInteger > @NotSoMagicNumber
Is there any way to do that?
Thanks!
...
how can we add a where condition to a linq subselect query.
i.e.
List<CallLog> callLog = CallLog.SampleData();
List<Contacts> contacts = Contacts.SampleData();
var q = from call in callLog
where call.Incoming == true
group call by call.Number into g
select new contacts {
contact....
I would like this SQL to be converted to LINQ. (it shouldl select rows from input which do not exist in table production based on 3 columns. If a column in both tables contains NULL, it should be considered as having the same value)
SELECT i.* FROM INPUT AS i
WHERE NOT EXISTS
(SELECT p.Agent FROM Production AS p
WHERE ISNULL(i.CustID,''...
Is there a better way to write this? I feel like I'm getting rusty with C# after doing a lot of JavaScript lately. Can this be improved?
foreach (var item in this.CartItems)
{
if (item.EffectivePrice != null)
{
this.CartItems[this.CartItems.IndexOf(item)].EffectivePrice =
CurrencyHelp...
I have an IEnumerable containing objects that have a groupnumber property. I want to be able to get a list of all objects that have duplicate groupnumbers e.g.
obj1: groupnumber=1 KEEP
obj2: groupnumber=2 DELETE
obj3: groupnumber=1 KEEP
I can use the following to get a list of all the duplicated groupnumbers
var duplicates = from...
Currently im trying to make my query short with reusable peice of code like this to check for post if it's eligible to display.
// Logic to check if post is eligible for display
public bool isEligibleForDisplay(Post n)
{
var pubDate = n.PUBLISH_DATE ?? DateTime.MinValue;
var endDate = n.END_DATE ?? DateTime.M...
Not that it would be better, but I'm trying to get my head around turning the following method syntax to query syntax to see the difference.
long diskSpace = Directory.EnumerateDirectories(@"c:\")
.SelectMany(Directory.EnumerateFiles)
.Sum(fileSize => new FileInfo(fileSize).Length);
...
I've got a simple class defined as:
public class IndexEntry
{
public bool HighScore { get; set; }
public List<IndexEntry> SubEntries { get; set; }
//Other properties, etc...
}
I now need to search through a List to find the one item that has its HighScore Property set to true. Since it isn't a flat list, but a Hierarchy whic...
I have the follow Linq query that is in a web application that was converted from .NET 1.1 to 3.5:
dim objListOfFilteredDataRows = from datarows as datarow in objDataSet.tables(0).rows _
where datarows("SomeColumn") = SomeValue
I have the exact same query in an application that was created using .NET 3....
I'm trying to learn a bit more about LINQ by implementing Peter Norvig's spelling corrector in C#.
The first part involves taking a large file of words (about 1 million) and putting it into a dictionary where the key is the word and the value is the number of occurrences.
I'd normally do this like so:
foreach (var word in allWords) ...
How can we change the underlying database for Linq based WebApp ?
for example:
When we release our web application, say to release from production, if using ADO.NET,
it is as simple as modifying connection string in web.config to point towards the live Database in use. The databases are almost identical, other data stored..
What and h...
Hi , i have the following piece of code, that for some reason that i'm unaware of, doesn't populate the LINQ resultset to the listbox (and there are many results in this list), however, i bind it to the original datatable, it works well. any ideas:
DataTable t = _partitionsDataSet.Tables[0];
var customizedPartitions = ...
i am having a small problem here.
The table which dbml (LinqToSql designer) is using has columns (Foreign keys), for which it generates two objectsfor the coressponding Blogs table (1:1 association) in DB lmost same,
like
Table Authors: AuthorID INT, Name varchar(20), BlogID INT
And
TABLE BLOG: BlogID INT, Name varchar(MAX)
Bl...
Being new to LINQ, I created a couple queries and would like to combine them into one, but I am not sure how to do it. Here they are:
var u = dc.Users.Where(w => w.UserName == userName).SingleOrDefault();
var m = dc.Memberships.Where(w => w.UserId == u.UserId).SingleOrDefault();
m.PasswordQuestion = securityQuestion;
m.PasswordAnswer...
I have my tags desinged like this in my database:
Table: Item
Columns: ItemID, Title, Content
Table: Tag
Columns: TagID, Title
Table: ItemTag
Columns: ItemID, TagID
//example -- this is the right sidebar of stackoverflow
c# × 59279
sql × 14885
asp.net-mvc × 9123
linq × 4337
tags × 339
if I wanted to know the count of each ta...
Hello,
I have this LINQ query:
var agnts = (from a in db.agents select new { a.UserId, a.name }).Take(10);
How can I get randomly get 10 records from my agents table?
I have tried:
agnts = agnts.OrderBy(n => Guid.NewGuid());
but this doesn't seem to do anything.
I would appreciate anybody's help on this.
Thanks,
Louis
...