dynamic-linq

dlinq versus ADO.NET Entity Framework

I am about to finalize the design of my webapplication, i am building it as an n-tier architecture and i am posed with the question of using DLinq vs EFM. I would appreciate if someone could give me some expert advice on it. ...

Dynamic where clause in LINQ - with column names available at runtime

Disclaimer: I've solved the problem using Expressions from System.Linq.Expressions, but I'm still looking for a better/easier way. Consider the following situation : var query = from c in db.Customers where (c.ContactFirstName.Contains("BlackListed") || c.ContactLastName.Contains("BlackListed") || c.Add...

DLINQ- Entities being inserted without .InsertOnSubmit(...)?!

Hello, I ran into an interesting problem while using DLINQ. When I instantiate an entity, calling .SubmitChanges() on the DataContext will insert a new row into the database - without having ever called .Insert[All]OnSubmit(...). //Code sample: Data.NetServices _netServices = new Data.NetServices(_connString); Data.ProductOption[] te...

Dynamic LINQ with direct user input, any dangers?

I have a table in a ASP.NET MVC application that I want to be sortable (serverside) and filterable using AJAX. I wanted it to be fairly easy to use in other places and didn't feel like hardcoding the sorting and filtering into query expressions so I looked for a way to build the expressions dynamically and the best way to do this I found...

ASP.NET MVC Authorization based on role membership or data relation (ownership)

I'd like to extend the AuthorizeAttribute in ASP.NET MVC so that it supports the concept of a user's authorization being based on their role membership OR "ownership" of the data in question. I'm using LINQ2SQL for data access. There is a similar question at http://stackoverflow.com/questions/390930/asp-net-mvc-authorization-using-roles....

Building Dynamic LINQ Queries based on Combobox Value

I have a combo box in Silverlight. It has a collection of values built out of the properties of one of my LINQ-to-SQL objects (ie Name, Address, Age, etc...). I would like to filter my results based off the value selected in a combo box. Example: Say I want everyone with a last name "Smith". I'd select 'Last Name' from the drop down ...

Dynamic LINQ query using an Attribute

I have had some success getting the MSFT Dynamic Linq stuff to work, but now I need to create a "Where" clause that includes an Attribute. The error I get is "No applicable aggregate method 'First' exists" Here is my code: where = "Element(XName.Get(\"procedure\")).Attributes(XName.Get(\"code\")).First() = \"28002\""; var q2 = doc.El...

How to name fields using Dynamic Linq?

I have a huge query that is being made dynamically, but I want the select statement to not output the column names, buut custom values. FOr example, if I am doing a normal Linq query, I can do something like this: var v = from p in db.items select new { name = p.item_name, price = p.item_price }; which will give me the nice '.name' a...

How do I do a Contains() in DLINQ with a list of items?

I want to build a dlinq query that checks to see if a title has any number of items in it. I know you can do .Contains() with a list, but I need to check if the title contains any of the items, not if the items contain part of the title. For example: I have three items in the list "bacon, chicken, pork." I need the title of "chicken hous...

How can I supply a table name at runtime using LINQ to SQL?

I have to use LINQ to SQL and along with it a pure SQL classic query. And this SQL query has the Table from where my data will be generated, but I will not know this Table previously. It will be known in compile time. So how can I make LINQ understand from what Table I want to make the query? ...

Dynamic Linq - Setting orderby expression type at runtime

I'm using dynamic Linq and have the where clauses working. Now I'm looking to add orderby clauses but am having a problem being able to set the type of the dynamic expression. Below is working code that I have: class MyClass { public string Owner; public DateTime Inserted; } Expression<Func<MyClass, bool>> whereExpression = Dyn...

Access Linq result contained in a dynamic class

I'm using DbLinq which should be the equivalent of Linq2SQL for this question. I'm need to generate a Linq2SQL query where I specify the columns I want returned at runtime. I can achieve that using the Dynamic Linq extension methods but I can't work out how to extract the result. string someProperty = "phonenumber"; string id = "1234"; ...

LINQ Query or stored procedure to return max value in a stated column

Table like datetime a1 b1 x2 ... 07-01-2009 13:10 8 9 10 07-01-2009 13:11 8 8 2 07-01-2009 13:12 9 1 1 1 row per second for a whole day (=86400 rows); ~40 columns; all same format I'm looking for a way to retrieve a max value and the time for a column to specify. I'm looking for a way to...

LINQ Dynamic Expression API, predicate with DBNull.Value comparison

I have an issue using the Dynamic Expression API. I cannot seem to compare a DataTable field against DBNull.Value. The API is supposed to be able to "support static field or static property access. Any public field or property can be accessed.". However given the following query: var whatever = table1.AsEnumerable() ...

Strange Exception thrown using Dynamic Linq Entity Framework Query

I have a gallery entity framework class,and I'm attempting to use the Dynamic Linq Library posted on ScottGu's blog to query the entity set. The failing line of code reads: return context.Galleries.OrderBy(sidx + " " + sord).Skip(page * rows).Take(rows).ToList(); sidx=="Name", and sord=="desc". The Gallery object does have a propert...

Dynamic LINQ on a collection?

Hi there, I've a project which ask me to do such a BUG search engine but which is all dynamic. I mean I can have about 0 to 9 main "group" which have inside something like an infinite possibility of "where" with "OR" or "AND". First thing we think was to use Dynamic Linq which provide a good alternative to build dynamic query. All this ...

How to get Lamda in LINQ to actually filter for dynamic linq

Example-I have a person class Public Class Person Private _fname As String Public Property Fname() As String Get Return _fname End Get Set(ByVal value As String) _fname = value End Set End Property Private _lname As String Public Property Lname() As String Get Return _lname End Get S...

DynamicLinq OrderBy in n:m relation table

Hi, there is any way to order a query by a many-to-many relation table column in linq? and in scottgu's DynamicLinq? For example: Products: p_id, p_name Product_Order: p_id, o_id, quantity Order: o_id, o_name how can I query for order by Product_Order quantity? from p in model.Products order by p.Product_Order.quantity select p ...

Null Reference Exception in a Dynamic LINQ Expression

I am using the Dynamic Linq Library / Sample from Microsoft to do ordering on a list. So for example I have the following C# code: myGrid.DataSource=repository.GetWidgetList() .OrderBy(sortField + " " + sortDirection).ToList(); I have a case where my Object have a 0:1 relationship with another object, which has a property ...

Is the Specification Pattern obsolete when you can use Dynamic LINQ?

Wikipedia states that the Specification Pattern is where business logic can be recombined by chaining the business logic together using boolean logic. With respect to selecting filtering objects from lists or collections it seems to me that Dynamic LINQ allows me to accomplish the same thing. Am I missing something? Are there other be...