I've long since built a way around this, but it still keeps bugging me... it doesnt help that my grasp of dynamic LINQ queries is still shakey.
For the example:
Parent has fields (ParentKey, ParentField)
Child has fields (ChildKey, ParentKey, ChildField)
Pet has fields (PetKey, ChildKey, PetField)
Child has a foreign key reference to ...
This is really annoying...and I know it is something extremely simple...
1. I create a new Dynamic Data project.
2. I add a LINQ-to-SQL class and drag and drop some tables onto the class.
3. I open the global.asax.vb and uncomment the line:
DefaultModel.RegisterContext(GetType(YourDataContext), New ContextConfiguration() With {.Scaffold...
I'm actually using a join in linqtosql (via dblinq).
I'm trying to include a regular expression in the join part of the linq query.
from i in collectiona
join j in collectionb on Regex.IsMatch(i.name, j.jokered_name) equals true
(...)
I agree i can push the RegExp check in the where part of the linq query, but i was wondering if it i...
Hello everyone,
I am trying to figure out how to go about writing a linq query to perform an aggregate like the sql query below:
select d.ID, d.FIRST_NAME, d.LAST_NAME, count(s.id) as design_count
from tbldesigner d inner join
TBLDESIGN s on d.ID = s.DESIGNER_ID
where s.COMPLETED = 1 and d.ACTIVE = 1
group by d.ID, d.FIRST_NAME, d.LAST_...
I can't get this bit of logic converted into a Linq statement and it is driving me nuts. I have a list of items that have a category and a createdondate field. I want to group by the category and only return items that have the max date for their category.
So for example, the list contains items with categories 1 and 2. The first day (1...
How do you loop through IQueryable and remove some elements I don't need.
I am looking for something like this
var items = MyDataContext.Items.Where(x => x.Container.ID == myContainerId);
foreach(Item item in items)
{
if(IsNotWhatINeed(item))
items.Remove(item);
}
Is it possible? Thanks in advance
...
I want to do the following dynamically
Generate numbers from 1 to 100 and then select 25 random numbers from it and display it in a console. Any easy way to do so?
...
I am trying to figure out how to do a mixed-join in LINQ with specific access to 2 LINQ objects. Here is an example of how the actual TSQL query might look:
SELECT
*
FROM
[User] AS [a]
INNER JOIN
[GroupUser] AS [b]
ON
[a].[UserID] = [b].[UserID]
INNER JOIN
[Group] AS [c]
ON
[b].[GroupID] = [c].[GroupID]
LEFT JOIN
[GroupEn...
Hi guys,
I've got three tables:
cp_user (id, name)
cp_group (id, name)
cp_usergroup (user_id, group_id)
the classical m:n stuff.
Assume the following Data:
cp_user
1, Paul
2, Steven
cp_group
1, Admin
2, Editor
cp_usergroup
1, 1
1, 2
2, 2
So Paul is in the Admin AND Editor group, while Steven is just in the Editor group. I wan...
I'm using some code (available here on MSDN) to dynamically build LINQ expressions containing multiple OR 'clauses'.
The relevant code is
var equals = values.Select(value => (Expression)Expression.Equal(valueSelector.Body, Expression.Constant(value, typeof(TValue))));
var body = equals.Aggregate<Expression>((accumulate, equal) => Exp...
I have some code that returns unique elements in my dictionary, but I would also like to return the count of the duplicate elements. Basically change dictionary[key, uniqueelement] to dictionary[uniqueelement, count]. Here is my code that just returns the unique elements.
var uniqueItems = deviceInstances.Children.GroupBy(pair => pair...
I have two samples of code. One works and returns the correct result, one throws a null reference exception. What's the difference? I know there's some magic happening with capturing variables for the lambda expression but I don't understand what's going on behind the scenes here.
int? x = null;
bool isXNull = !x...
I'm going to start a new project which is going to be small initially but may grow to big over the years. I'm strongly convinced that I'm going to use ASP.NET MVC with jQuery for UI. I want to go for MySQL as database for some reasons but worried on few things.
I'm totally new to Linq but it seems that it is easier to use once you are f...
Hi,
I keep getting the same error: Entities in 'VlaamseOverheidMeterEntities.ObjectMeter' participate in the 'FK_ObjectMeter_Meter' relationship. 0 related 'Meter' were found. 1 'Meter' is expected.
I have the following table structure:
Meter 1 <- * ObjectMeter * -> 1 VO_Object
It is always the same scenario: The first meter is adde...
I'm currently working on an Web Application similar to Steamworks (if you don't know what it is, its a service for games to store Achievements, Stats etc).
The major problem I've run into in the development of this is the addition of new databases for games after the application has been deployed. I'm using LINQ-to-SQL to query the data...
I have two objects (Foo and Bar) that have a one-to-zero-or-one relationship between them. So, Foo has a nullable foreign key reference to Bar.ID and a (nullbusted) unique index to enforce the "1" side. Bar.ID is an int, and so Foo.BarID is a nullable int.
The problem occurs in the LINQ-to-SQL DBML mapping of .NET types to SQL datatypes...
I am new to LINQ, and so am struggle over some queries that I'm sure are pretty simple. In any case, I have been hiting my head against this for a while, but I'm stumped.
Can anyone here help me convert this T-SQL query into a LINQ query? Once I see how it is done, I'm sure I'll have some question about the syntax:
SELECT BlogTitle
FRO...
Given i have a class like so in my Data Layer
public class GenericRepository<TEntity> where TEntity : class
{
public MyDataContext DataContext {get;set;}
[System.ComponentModel.DataObjectMethod(System.ComponentModel.DataObjectMethodType.Select)]
public IQueryable<TEntity> SelectAll()
{
return DataContext.GetTable<TE...
I have a simple NHiberntate linq query:
var queryable = session.Linq<Product>().Where(p => p.Active);
Product[] products = queryable.ToArray();
The moment the ToArray() is executed the session becomes dirty (session.IsDirty() returns true). If the transaction is commited there is an UPDATE SQL query generated for each product.
Why ar...
Hi folks, I've got a data table with columns in which include Item, Category and Value (and others, but those are the only relevant ones for this problem) that I access via LINQ in a C# ASP.Net MVC app. I want to transform these into a matrix and output that as a CSV file to pull into Excel as matrix with the items down the side, the cat...