linq

OData EndPoint/DataService Using IEnumerable<IQueryable>

I am using NHibernate with NHibernate.Linq, and have a bunch of dynamically loading modules each with their own POCO's and Mappings (ClassMap<POCO>). I have created OData services before, but normally with a datacontext and IQueryable as Properties/Getters. What I want is to create the service by passing in IEnumerable, into the constr...

Compile error when calling ToList() when accessing many to many with Linq To Entities

I can't figure out what I am doing wrong. I have the following method: public IList<WObject> GetRelationshipMembers(int relId) { var members = from r in _container.ObjectRelationships where r.Id == relId select r.WObjects; return members.ToList<WObject>(); } Thi...

Does LINQ to Objects caching?

Does LINQ to Objects queries cache by LINQ provider when it execute for the second time? ...

How Manage Big Linq DataContext ?

Hi The major subject in .net programs is "How manage memory for best performance". so Microsoft use garbage collector in .net and with that, we don't need to do something for managing memory(or better say we can use GC easily) But when you develop big project(business app), you make too many tables and database for your own project. s...

Select more then one node from XML using LINQ

I have such XML <root> <content> .... </content> <index> .... </index> <keywords> .... </keywords> </root> But I need to select just and nodes. <content> .... </content> <index> .... </index> I found out how to select just one node. XElement Content = new XElement("content"...

Filtering subsets using Linq

Hi All, Imagine a have a very long enunumeration, too big to reasonably convert to a list. Imagine also that I want to remove duplicates from the list. Lastly imagine that I know that only a small subset of the initial enumeration could possibly contain duplicates. The last point makes the problem practical. Basically I want to filter ...

How to convert a 2-d array into a dictionary object

Hi, I have an array of type string that looks like this: "test1|True,test2|False,test3|False,test4|True". This is essentially a 2d array like so [test1][True] [test2][False] [test3][False] [test4][True]. I want to convert this into a dictionary<string,bool> using linq, something like: Dictionary<string, bool> myResults = results.Split...

Castle ActiveRecord / NHibernate Linq Querys with ValueTypes

Given the following code for our Active Record Entites and ValueTypes Linq is not working for us. [ActiveRecord("Person")] public class PersonEntity : ActiveRecordLinqBase<PersonEntity> { string _name; [Property("Name", Length = 20, ColumnType = "string", Access = PropertyAccess.FieldCamelcaseUnderscore)] public Name Name ...

After grouping by, can I refer to the elements of the original IEnumerable in a LINQ query?

Example: from OriginalObject in ListOfOriginalObjects group new CustomObject { X = OriginalObject.A, Y = OriginalObject.B } by OriginalObject.Z into grouping select new GroupOfCustomObjects { Z = grouping.Key, C = OriginalObject.C, group = grouping } In the select part of the query, I'd like to add a property (Original...

LINQ TO SQL, Dynamic query with DATE type fields

Hello, I'm building a query with the LINQ dynamic library so I don't know how many potential parameters will I have and I get an error when trying to query DATE type fields: Operator '>=' incompatible with operand types 'DateTime' and 'String' When I step through the debugger in the Dynamic.cs it shows that the value is of type string...

LINQ to SQL Foreign Key Constraint conflicts

I'm having a problem with LINQ. I have 2 tables (Parent-child relation) Table1: Events (EventID, Description) Table2: Groups (GroupID, EventID(FK), Description) Now i want to create an Event an and a child. Event e = new Event(); e.Description = "test"; Datacontext.Events.InsertOnSubmit(event) Group g = new Group(); g.Description =...

ASP.NET MVC Inserting object and related object into 2 tables

I have two tables: Users and UserOwners. Table UserOwners contains list of users that certain user created (list of child-users) - or to be more precise, it contains UserOwnerID and UserID fields. So, now I want to create a new user... in Controller I have something like this: var userOwner = accountRepository.GetUser(User.Identity.Nam...

Database choices

I have a prickly design issue regarding the choice of database technologies to use for a group of new applications. The final suite of applications would have the following database requirements... Central databases (more than one database) using mysql (must be mysql due to justhost.com). An application to be written which accesses the...

LINQ .Cast() extension method fails but (type)object works.

To convert between some LINQ to SQL objects and DTOs we have created explicit cast operators on the DTOs. That way we can do the following: DTOType MyDTO = (LinqToSQLType)MyLinq2SQLObj; This works well. However when you try to cast using the LINQ .Cast() extension method it trows an invalid cast exception saying cannot cast type Lin...

Linq generic Expression in query on "element" or on IQueryable (multiple use)

Hi, I have the following expression public static Expression<Func<T, bool>> JoinByDateCheck<T>(T entity, DateTime dateToCheck) where T : IDateInterval { return (entityToJoin) => entityToJoin.FromDate.Date <= dateToCheck.Date && (entityToJoin.ToDate == null || entityToJoin.ToDate.Value.Date >= dateToCheck.Date); } IDateInt...

Is there a way to make this C# method shorter and more readable with the help of Linq?

The following works, but I figured - since it is all based on IEnumerable, Linq can come handy here is well. By the way, is there an equivalent to Directory.GetFiles() which would return an IEnumerable instead of the array? If it exists, then would it make the code run any faster? The last part of the question is inspired by Python langu...

Getting A LINQ .InsertOnSubmit To Work

Hi SO, I'm trying to get an insert to work using LINQ and am having some difficulties. I am using this example to base my code: http://msdn.microsoft.com/en-us/library/bb763516.aspx I have my data object set up, but don't know what's going on when db.Orders.InsertOnSubmit is executed. How can I create this db object to insert a dat...

LINQ Query Help!

Can someone hep me converting the following SQL query into LINQ? select convert(varchar(10),date,110) as 'Date', max(users) as 'Maximum Number of Users', max(transactions) as 'Maximum Number of Transactions' from stats where datepart(Year, Date) = '2010' group by convert(varchar(10),date,110) order by conv...

Dictionary<string,string> to Dictionary<Control,object> using IEnumerable<T>.Select()

I have a System.Collections.Generic.Dictionary<string, string> containing control ID and appropriate data column to data bind: var dic = new Dictionary<string, string> { { "Label1", "FooCount" }, { "Label2", "BarCount" } }; I use it that way: protected void FormView1_DataBound(object sender, EventArgs e) { var row = ((Dat...

How do I return the ancestors of an object with LINQ?

I have a District class that looks like this: public class District { public int Id { get; set; } public string Name { get; set; } public District Parent { get; set; } public IEnumerable<District> Ancestors { get { /* what goes here? */ } } } I would like to be able to get a list of each District's ancestors. So if Dis...