Hello there,
I have a little problem which i can't solve.
I want to use an SQL-In-Statement in Linq. I've read in this Forum and in other Forums that I have to use the .Contains (with reverse-thinking-notation :-)).
As input i have a List of Guids. I first copied them into an array and then did something like that :
datatoget = (from p...
I'm having trouble with a LINQ to SQL query getting the min value using Visual Basic. Here's the SQL:
SELECT RC.AssetID, MIN(RC.RecCode) AS RecCode, JA.EngineerNote from JobAssetRecCode RC
JOIN JobAssets JA ON JA.AssetID = RC.AssetID AND JA.JobID = RC.JobID
WHERE RC.InspState = 2 AND RC.RecCode > 0
AND RC.JobID = @JobID
GROUP BY RC.Asse...
I just upgraded from VS2008 to VS2010. In the process, I allowed it to upgrade my DLL's to 4.0. I've decided that wasn't a good idea and now I've rolled back.
It all works fine in VS2010, but when it hits my CI server (CruiseControl.Net), I get an error of:
The type or namespace name 'Linq' does not exist in the namespace 'System' (a...
I am trying to convert the following stored proc to a LinqToSql call (this is a simplified version of the SQL):
INSERT INTO [MyTable]
([Name], [Value])
SELECT
@name, @value
WHERE
NOT EXISTS(SELECT [Value] FROM [MyTable] WHERE [Value] = @value)
The DB does not have a constraint on the field that is getting checked for so in ...
public class Mailing
{
public string To { get; set; }
public string AttachmentPath { get; set; }
public int AttachmentCount { get; set; }
}
giving this structure i have a IList<Mailing> mailingList where To has dups and the AttachmentPath is unique per To.
i need to send emails to the mailingList where each unique To has m...
Context: ASP.NET MVC 2.0, C#
At the moment I use following pattern:
using (var db = new MyDatabaseDataContext()) {
var model = new MyPageModel();
model.player = db.blah.blah.blah;
model.info = db.blah.blah.blah;
model.bossKillCount = db.blah.blah.blah;
}
It works fine, one problem is that I have to redefine those mod...
My code works for ORs as I've listed it below but I want to use AND instead of OR and it fails. I'm not quite sure what I'm doing wrong. Basically I have a Linq query that searches on multiple fields in an XML file. The search fields might not all have information. Each element runs the extension method, and tests the equality. Any ...
I've a nice situation, I think at beginning this a usual query but I'm having some problem trying to solve this, the situation is:
I've a list of "Houses", and each house have a list of "Windows". And I want to filter for a catalog only the Houses witch have a Blue windows, so my extension method of House is something like:
public stat...
var list = (from i in _dataContext.aspnet_Users.Include("aspnet_Membership") where i.UserName.Contains(userName) select i ).ToList();
if userName="" then nothing return. how can i do that if empty string then return all records?
...
I get this error
Cannot add an entity with a key that is already in use
when I try to save an Item
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Item item)
{
Global.DataContext.Items.Attach(item);
Global.DataContext.SubmitChanges();
return View(item);
}
That's because I cannot attach the item to the global DataCo...
Hey,
How do i create a new row in a table which have a relationship with another table?
I have an Employees table and a EmployeeProjects table. One Employee can have 1-* EmployeeProjects.
Now i want to create a new EmployeeProject which relates to an Employee. How do i do this?
Here is want i have tried so far:
var ep = new Employee...
how can i do in linq:
IEnumerable<DataRow> query =
from rec in dt.AsEnumerable()
where rec.Field<decimal>("column2") == 1 && foo(rec.Field<decimal>("column1"))
select new {
column1 = rec.Field<decimal>("column1"),
column2 = rec.Field<decimal>("column2"),
column3 = rec.Field<d...
I need to get the list of records that does not starts with alphabets. i.e. Which starts with numeric and any special character.
I am using asp.net mvc (C#) for my application.
Whats the simple linq query to get this list?
...
I am using PredicateBuilder to build an expression tree so I end up with an Expression(Of Func(T, Boolean)).
I can't pass that Expression into a WHERE function like this:
invoices.Where(predicate)
Where predicate is an Expression(Of Func(Invoices, Boolean)).
The compile error I am getting is:
Value of type: Expression(Of Func(Invoic...
After upgrading to ReSharper5 it gives me even more useful tips on code improvements. One I see everywhere now is a tip to replace foreach-statements with LINQ queries. Take this example:
private Ninja FindNinjaById(int ninjaId)
{
foreach (var ninja in Ninjas)
{
if (ninja.Id == ninjaId)
return ninja;
}
...
Hi,
I have an SQL database, which is a "feeder" table. I put records in said table, a 3rd party package consumes (and deletes) them. All hunky dory - until the 3rd party package isn't running. In thinking about how to detect that, I thought to myself... "well... what if I read all the keys in the table (its not very big - max a few doze...
I have seen the reverse of this question quite a few times, but have not seen how to do what I would like.
Suppose I have the following code:
var myNewData = from t in someOtherData
select new
{
fieldName = t.Whatever,
fieldName2 = t.SomeOtherWhatever
};
If I wish t...
I read other posts on similar problem on using SingleOfDefault on Linq-To-Entity, some suggested using "First()" and some others suggested using "Extension" method to implement the Single().
This code throws exception:
Movie movie = (from a in movies
where a.MovieID == '12345'
select a).SingleOrDefaul...
Hi,
I have object A which contains multiple instances of object B, which in turn contains multiple instances of object C. I need to write a function which, given Object A needs search through instances of objects B and objects C and find a particular object C. How would I do this using LINQ?
...
Not sure if I am using the correct term, but it's not child/parent since they aren't nested objects. In my application I've got a User, UserUserGroup, and UserGroup objects which are pretty standard, UserUserGroup is a linking object with corresponding IDs. I am using Linq-to-SQL so unforunately it doesn't used nested objects, but it sti...