I have an interface, called IRepository.
One of the methods in this interface is:
IEnumerable<T> FindByQuery(Expression<Func<T, bool>> predicate);
I then have (for example) an IUserRepository, that implements IRepository.
In my implementation of IUserRepository, currently called LinqToSqlUserRepository, i have implemented the FindByQ...
I have a DataTable with rows of data. I have a class with properties that match the row column names.
How can I have a List that is populated from the DataTable Row information?
Do I call something like (MyType)new XmlSerializer(typeof(MyType)).Deserialize(new XMLReader(Table.WriteXML()));
...
I have a Linq query that orders by a datetimeoffest. The goal is to have the one that is NULL at the top, followed by most recent, 2nd recent, and so on. I started with this.
orderby item.Date descending
Doing it this way the NULLs go to the bottom. So I changed it to this.
orderby (item.Date.HasValue ? item.Date.Value.Ticks : long.M...
I'm trying to get a query going that will search multiple tags. The tags are db based and I've related them to the entity with a junction table. If I search with 1 tag, I get the correct results, but if I search with 2 tags, I only get the entities that match the second tag.
Here's the C# code that builds the IQueryable:
var awTable ...
I am trying to chain multiple compiled linq queries together. I have succeeded in chaining two queries together, but I cannot get a chain of three to work correctly. So here is a reduction of my code to recreate the issue. My two questions are: 'Why isn't this working?' and 'Is there a better way to keep the performance benefit of com...
I'm learning Linq to SQL and I'm having trouble grasping it. I'm trying to simply return a single (boolean) value in C# with a Linq query.
I want to see if the owner of a story would like an email notification sent when new comments are added. I would like the method that contains the Linq to SQL to return a boolean value.
public bo...
I'm familiar with the problem of modifying a collection while looping over it with a foreach loop (i.e. "System.InvalidOperationException: Collection was modified"). However, it doesn't make sense to me that when I use Linq to create a List of keys to delete from a dictionary, then loop over my new List, I get the same exception.
Code ...
I am using Linq to Entities in a method and returning specific columns of data from the method. I don't know what type I'll be returning so I rigged it to return a List. If someone knows a better way than the way I rigged it, PLEASE let me know. See the code below.
After returning this data, I then need to iterate through the colum...
I have a list of Items, given by Linq from the DB.
Now I filled a ComboBox with this list.
How I can get an empty row in it?
My problem is that in the list the values aren't allowed to be null, so I can't easily add a new empty item.
...
Hello
I have an application with user and admin sections. If an admin updates data with the help of sql datasource then it's updated the database. However, when we retrieve data with linq query then it's showing its old value rather than the updated value.
After some time, the linq query automatically shows the correct value.
I think ...
I have the following setup: Tasks, Accounts and Groups tables. Tasks can be assigned to both individual accounts and groups. I've made two supporting tables: TasksAndAccounts and AccountsInGroups. TasksAndAccounts table has the following fields: TaskId, AccountId, GroupId and AccountsInGroups has AccountId and GroupId fields. I'm trying ...
Can I absolutely abandon SQL if I choose LINQ?
If Yes, then, Should I absolutely abandon SQL if I choose LINQ?
After making a connection to RDBMS using DataContext-class, do I actually need SQL?
...
I have a custom list which inherits from Generic.List<T> like this:
public class TransferFileList<T> : List<TransferFile> { .. }
When I set (where 'Files' is a TransferFileList<T>):
var files = uploadResponse.Files.Where(x => !x.Success).ToList()
the 'files' object resolves as System.Collections.Generic.List<TransferFile>, not Tran...
Hi, I'm trying to work out how to create a query using Linq to NHibernate.
I have two classes like this:
public class Foo
{
private ISet<Bar> _bars = new HashedSet<Bar>();
public virtual ISet<Bar> Bars
{
get { return _bars; }
set { _bars = value; }
}
}
public class Bar
{
public string Name { get; se...
Let's ay I have this query:
var results = from row in db.Table select row;
How can I access this:
string name = results[0]["columnName"];
...
For some integration tests I want to use LINQ to SQL to drop/re-create the test database. I've had this working fine before, however in this project the database is split up into several schemas.
When I try to run the ctx.CreateDatabase() command I'm getting this exception:
The specified schema name "xyz" either
does not exist or...
I'm currently building a detailed search and I am trying to figure out how to compose my Linq query to my Entity.
basically I have users that can select 1* items in a list control.
the part I can't wrap my head around is the following:
how can I dynamically build a Where AND( field is equal to this OR field is equal to this OR...) cla...
I am getting "The null value cannot be assigned to a member with type System.Int32 which is a non-nullable value type" When executing Sum() of my empty statement.
ResultView works fine, but either
var r = from v in DataContext.Visits
join bs in DataContext.BaseContents on v.BaseContentID equals bs.Id
where (bs.CreatedBy ...
I'm attempting to write a linq query which uses several tables of related data and have gotten stuck.
The expected result: I need to return the three most populous metropolitan areas per region by population descending.
tables w/sample data:
MetroAreas -- ID, Name
2, Greater New York
Cities -- ID, Name, StateID
1293912, New York City...
Don't know what's wrong here, when I run the application it says "Specified method is not supported" pointing at "var result in query" in foreach loop. Please help...
var query = from c in entities.Customer
select c.CustomerName;
List<string> customerNames = new List<string>();
foreach (var result in query)
{
customerN...