Hi,
I have two tables in my database - Category and Department which both contain the same columns - ID, Name and Code.
I can create a new entity model using the Visual Studio 2008 designer and add the Department and it works fine - I can query the database using LINQ, alls good.
When I update the model and add the Category table, th...
Hi,
One of the things that you have beaten into you as a junior developer is that you never, ever do a "SELECT *" on a data set, as it is unreliable for several reasons.
Since moving over to Linq (firstly Linq to SQL and then the Entity Framework), I have wondered if the Linq equivalent is equally frowned upon?
Eg
var MyResult = fro...
Urgent: I have to work out how to write the following SQL query usingLINQ query or method syntax. (Edit: This is to return a list of latest AgentActivities for all Agents). Any help will be much appreciated.
SELECT
a.[AgentActivityId],
a.[AgentId],
a.[ActivityId],
a.[StartedAt],
a.[EndedAt],
a.[Version]
FROM
[dbo].[AgentActivity...
Traversing a nested LINQ query in of anonymous objects in C# view via ASP.NET MVC
Hi, done a lot of searching and reading but still require some specific information.
I have the following code:
List<DateTime> range = getRangeCollection();
var range = (
from years in rangeData
group years by ye...
public static IEnumerable<UIElement> Traverse(this UIElementCollection source)
{
source.OfType<Grid>().SelectMany(v => Traverse(v.Children));
//This is the top level.
foreach (UIElement item in source)
{
yield return item;
}
}
This never returns anything recursively. I have b...
Ok, first I thought I had a problem with how I was querying things. But apparently the problem lies in how linq translates my query to sql.
Here's my linq:
var items = (from p in ctx.bam_Prestatie_AllInstances
join q in ctx.bam_Zending_AllRelationships on p.ActivityID equals q.ReferenceData
join r in ctx.bam_Z...
I am a bit curious as to which is considered "best practice" when it comes to FirstOrDefault.
I've already seen this question, which is similar to the question I have, but not close enough that it answers my question.
Which of these is "better code"? and why?
var foos = GetMyEnumerableFoos();
var foo1 = (from f in foos
where f.B...
Firstly, apologies for the bad question title - not entirely sure if I am asking the correct thing.
Normally I can do the following to access a field:
MyTables table = dc.MyTables.SingleOrDefault(p => p.id == someId);
somevalue = table.samplefield;
In this instance the variable somevalue would end up having the value of the field sam...
Hi Guys. I have a linq question (linq to sql). I have the following peice of code which works fine;
var queryx = (from sa in d1.SampleAttributes
where nodeTable.ToList().Distinct().Contains(sa.client_post_code_prefix)
select sa.SampleId).Distinct();
Note: nodeTable is of type IQueryabl...
How do I specify the type of the range variable in a linq query?
...
The title and tags of this post may be incorrect since my solution may end up being more MVC Controller - Model related instead of LINQ related...
I am building an MVC (not that the platform is important) site to display Invoices and the Invoice Details for approval before being paid. Basically this gives me a standard Master-Detail dat...
I have an object which has a property that contains an IEnumerable of objects. Each object in the IEnumerable has a property that is also an IEnumerable. I am attempting to capture a larger list of the inner property. Unfortunately, the lambda expression that I am using is returning an OrderedEnumerable. I'd like to just retrieve a simpl...
So I have this query. Both currentSurveyors and surveyorsInState are arrays of the same type. currentSurveyors could have 0 or more items. I want to return all the surveyorsInState except if that entry is in currentSurveyors. What am I doing wrong?
from current in currentSurveyors
from surveyors in surveyorsInState
...
Hello,
Given this xml:
<?xml version="1.0" encoding="utf-8"?>
<EntityDefinition xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<components>
<component xsi:type="TypeA">
<Property1>100</Property1>
</component>
<component xsi:type="TypeB">
<Property2>100</...
I've written a class that inherits from ObservableCollection<T>. I would like to be able to use the LINQ extensions methods like FirstOrDefault, like what you may get if you inherit from an implementation of IEnumerable<T>, or List<T>. How would I accomplish this?
...
Hi
I noticed when I look at say a result I got back from my database using linq to sql all fields like my primary key that is an auto increment field is shown as hex in my debugger.
So like I will see in the debugger 0x00000006 instead of '6'. Is there any particular reason why? Kinda through me off guard when I wanted to take my resul...
Is it possible to Mock a Linq Expression via Moq using a Generic class such as ~1Repository. ~IRepository being something that is injected via an IoC such as StructureMap or Windsor?
CODE TO TEST:
var person = _repository.Find<Person>()
.Where(p => p.Id == person.Id).SingleOrDefault();
TEST:
var rep...
If I have two databases and create a linked table (synonym) in one of them to the other one and then wrap that synonym in a view, will there be a performance issue? The reason I want to do this is to have SQLMetal see the synonym and generate a linq entity for it. The database are on the same server. Also if I did this 100+ times, all...
I have a WPF application that uses LINQ-to-SQL on a local .MDF file. This solution is simple, easy, and effective, i.e. I set up my model once, then read/write data anywhere via LINQ:
using (var db = Datasource.GetContext())
{
oldItem = (from i in db.Infos
where i.Id == TheId
...
I have a set of Data with columns such as below
OffName,RO1,RO2,RO3
To explain further i use sample data as below:
OffName RO1 RO2 RO3
A John Jack Rob
B Earl John Carl
C Rob Chris Kenny
D Rodney Carl Jacob
RO stands for Reporting Officer. Each Officer reports to upto 3 RO's.i need to make...