I like to fetch the data with eager-loading using Linq2SQL. The code is similar as :
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Product>(c => c.ProductCompanies);
options.LoadWith<Product>(c => c.OrderDetails);
db.LoadOptions = options;
IEnumerable<Product> products = db.Prod...
I have a program that stores data in objects in memory that you can think of as small db in memory. I would like to use LINQ to Objects to run some simple queries on the in memory objects. Is there a preferred structure that I should use for the in memory objects. Are there any good resources that I should read before I get to far into t...
I'm building a Silverlight 2 application and I need to bind some images to Image object declarated in XAML. I'm doing some other binding in the application and it works just fine, I'm having problem with only images!
This is it's XAML:
<Image Source="{Binding Path=ThumbNail}" Style="{StaticResource ThumbNailPreview}" />
And this is t...
Is it beneficial to use multicolumn (composite) primary keys for a many to many relationship table when using Linq to SQL?
Or should I just add an identity column as a non-clustered primary key and index the FK columns appropriately?
...
In this code:
Expression<Func<int, bool>> isOdd = i => (i & 1) == 1;
what is the meaning of (i & 1) == 1?
...
This is in response to this question in the answers section of another question.
I have a collection of Orders, each Order a collection of OrderItems, and each OrderItem has a PartId. Using LINQ how do I implement the following SQL statements:
1) Select all the orders that have a specific part ID
SELECT *
FROM Order
WHERE Id in (SELEC...
Hi folks,
I'm trying to retrieve a list of Id's from a collection that is a few levels deep in an object heirachy. When i try to do a ToList(), I keep getting an EntityList<> retrieved instead .. which means it's not allowing me to retrieve an instance's BarId property because the EntitySet is a Enumerable, not a single instance object....
the following code compares two lists which are sorted in descending order to find the removed entries.
fullorderbook.asks is the previous list of orders which may contain the removed orders.
orderbook.asks is the currect list of orders which contains the current state.
So the algorithm simply loops on the fullorderbook.asks and compa...
I've got an object of type A which consists of a list of objects of type B:
class A { list<B> Alist;}
class B { string C; string D;}
In my program I have a list of A objects:
list<A> listOfA = computeAList();
and I would like to select all the C strings in that list. The following statement I hoped would give me the result I wante...
I thought that the purpose of using Linq2Nibernate was to return IQueryable and build up an expression tree. I am not sure if this is correct or not.
Why would anyone use Linq2Nibernate if they are not going to return IQueryable?
What else would it be used for?
I would love some more input on this topic
Linq For Nhibernate
...
I was given a database design which stores information about an organization and any changes that have happened or will happen to the organizations. Since pretty much anything can change about an organization, there is one table that only contains the unique OrganizationID's in a table called "Organizations". The changes to that organiza...
Hi,
I have a base class called LabFileBase. I have constructed a List and have added my derived classes to it. I want to search the List for a particular object based on a key I've defined. The problem I'm having is how do you downcast in a LINQ expression?
Here is some sample code:
public abstract class LabFileBase
{
}
public cla...
I'm new to Linq to EntityFramework, one question in Linq2EntityFramework I have is when or if to dispose the ObjectContext. The reason I ask this question is that normally in my DAL I have code like
public List<User> GetUsers()
{
using (MyEntities db = new MyEntities()) //where MyEntities inherits ObjectContext.
{
...
Linq is an awesome addition to .NET and I've found it has served me well in many situations even though I'm only beginning to learn about how to use Linq.
However, in the reading I've been doing about Linq, I've discovered that there are some subtle things a developer needs to keep an eye out for that can lead to trouble.
I've included...
Consider this:
var me = new { FirstName = "John", LastName = "Smith" };
This is fine as we can then do this:
Console.WriteLine("{0} {1}", me.FirstName, me.LastName);
However we can't do this:
public T GetMe()
{
return new { FirstName = "John", LastName = "Smith" };
}
because we don't know the type of T.
We could do this:
p...
I plan on using this in a subquery but can't figure out the correct syntax to translate the following query into LINQ:
select ChapterID, min(MeetingDate)
from ChapterMeeting
group by ChapterID
...
Hi. I have the following DB:
Posts which have an Id, Tags also with Id, and TagsToPosts table which have TagsToPosts.PostId => Posts.Id and TagsToPosts.TagId => Tags.Id FK relations.
I need to delete multiple items from TagsToPosts in following way.
I'm creating IList<Tag> newTags by parsing a string. Each tag have it's name. I want to d...
I have a C# Queue<TimeSpan> containing 500 elements.
I need to reduce those into 50 elements by taking groups of 10 TimeSpans and selecting their average.
Is there a clean way to do this? I'm thinking LINQ will help, but I can't figure out a clean way. Any ideas?
...
If I need generate a fairly large dataset using LINQ and it may take a while (say a few seconds) and I need to (would like to) generate feedback to the use as to %'age done, is there an easy/ preferred way to do this?
Example, say I have list A with 1000 cars and list B with 1000 trucks and I want to select all possible ordered (car, tr...
I am using LINQ to join 2 datatables. I am trying to get back only 1 field from dtTable2 and all the fields from dtTable1. When this code executes, I have two columns. The first column contains the value from dtTable2.field2 and the second column has the value "System.Data.DataRow". I know that if I explicitly specify the columns in ...