score:3
var count = 50;
var alreayused = from au in repository.getentity<alreadyused>()
select au.id;
var notused = (from nu in repository.getentity<sample>()
where !alreadyused.contains(nu.id) && nu.references.count() > 0
orderby nu.name
select new customclass
{
cname = nu.name,
cid = nu.id
}).take(count).toarray();
notice that i added "nu.references.count() > 0"
i assume that you setup the association relationship called references correctly in your data model so that there are many "reference" objects in for every sample object.
score:0
you should be able to use the same technique from your alreadyused sample. eg:
var reference = from r in repository.getentity<reference>()
select r.id;
var notused = (from nu in repository.getentity<sample>()
where !alreadyused.contains(nu.id)
&& reference.contains(nu.id)
select new customclass
{
cname = nu.name,
cid = nu.id
}).take(count).toarray();
however, if you do have an association made between the sample table and the reference table, then you should probably use paul's method.
score:0
this should achieve what you are looking for. of course there are many ways to do it. personally i'd write it this way.
var items = (from r in repository.getentity<reference>()
join s in repository.getentity<sample>()
on r.fkid equals s.id
where !repository.getentity<alreadyused>().contains(s.id)
orderby s.name
select new customclass
{
cname = s.name,
cid = s.id
})
.take(count)
.toarray();
Source: stackoverflow.com
Related Query
- Help with linq to sql query
- Help with this LINQ to SQL query
- help with linq to sql many to many query
- How do I most elegantly express left join with aggregate SQL as LINQ query
- linq to sql query with multiple where parameters
- Simple sql to Linq query with group by and aggregate functions
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- Optimize SQL generated by LINQ Query in Entity Framework 4.1 with one-to-many associations
- C# Linq query help removing foreach loops creating cleaner code
- Populate Excel with data from LINQ to SQL query
- Determine the source DataContext for a Linq to Sql query
- Retrieve and print data from dynamic sql query with linq
- Help with Linq query
- How to get SQL query into LINQ form in C# code
- Complex LINQ to SQL Query with dates
- Help with Linq and Generics. Using GetValue inside a Query
- Need help with LINQ to SQL WHERE-clause on foreign table
- Linq to Sql query with multiple aggregations
- Need help with LINQ query and ASP.NET MVC?
- linq to sql query help - common values
- Convert sql query with multiple inner joins to LINQ
- Reuse Linq to SQL code with entityframework
- Identify source of linq to sql query
- Need help in converting SQL query to LINQ
- Linq sub query when using a repository pattern with EF code first
- Linq to sql as object data source - designer problem with partial classes
- help with linq query
- Help converting an sql query into LINQ
- SQL query with ROW_NUMBER not efficient in LINQ
- Getting single result from a query with anonymous types in Linq To Sql
More Query from same tag
- How to cast a Linq Dynamic Query result as a custom class?
- Is it possible to use Full Text Search (FTS) with LINQ?
- Selecting item from an IEnumerable
- using Any() with IQueryable List takes long time when executing?
- Select select query
- #Order by Not Null using expression Extension linq
- Wildcard search in using Lambda in EF
- Listing in WCF Entity
- Simplest Way To Do Dynamic View Models in ASP.NET MVC 3
- Problem merging IEnumerable<T> using Lambda expressions
- Integrate NULL check in LINQ
- How can I use LINQ to find a DataGridView row?
- Is it possible to simplify this LINQ statement
- How to update a database using LINQ to SQL?
- linq returning IEnumerable<{Object,Object}> from a function
- Expression<Func> method gives convertion error when used in linq query
- WCF Data Services : add two new objects to the database with links between them
- C# compare lists in a resource efficient way
- DateTime Error When Saving Changes to DB
- one search button and two text boxes if statement logic
- C# rearrange List by pattern
- Finding list of unique subsets of a given list of integers
- Microsoft.CSharp.RuntimeBinder.RuntimeBinderException Error
- Linq to SQL and Entity Framework in Same project
- How can I define variables in LINQ?
- Access LINQ-2-SQL DataContext in entity class
- LINQ to SQL-- Best learning resources?
- Getting an IList<field_type> from IList<object_type>
- How to update an existing item in SQL database using linq?
- Can not run basic LINQ query