I need to have "Where" Linq functionality in my own code.
Let me explain: we have an application that lets users write the so-called "user code", which is code in C# that will be picked up by the app and compiled and run at runtime.
In user code, I need to be able to specify an SQL condition. A special case is the condition on a date...
Follow up question to this:
http://stackoverflow.com/questions/1488414/linq-combine-left-join-data
Say I have the following db tables:
Users
-------
UserId (PK)
UserName
Roles
-----
RoleId (PK)
RoleName
UserRoles
---------
UserId (PK)
RoleId (PK)
Users 1-M UserRoles M-1 Roles
Using LinqToSQL, I can return the following set (thanks...
Hi,
I want to use a generic repository to standardise some of my data access.
What I want is to be able to have a function defined in the interface representing the basic fields of my entity, so that I can use it to filter the results. This should be compilable into Linq-To-Sql.
e.g.
interface IEntity {
Expression<func<bool>> Filter...
I am trying to sort a set of Users. I have access to the sorting property and direction (asc, desc). My current order by query is below. But as you can see it doesn't account for the sort direction. How do can I build this expression without having to use Dynamic Linq, or adding another set of statements for "asc" or "desc" sort directio...
I am working on an mvc app that uses some silverlight to supplement a page and instead of having to maintain two separate linq to sql classes I want to add a reference to the main project from the silverlight project but this can't be done through the normal method of just adding a reference, anyone have a workaround?
...
In my code I have multiple objects being added to the repository, I have tried running the repository Save() function one time at the end of all the loops, and also calling it after every object that is added. But either way I still get a SqlDateTime overflow when the db.SubmitChanges() in the repository .Save()... any idea?
SqlDateTim...
In my application I have 2 entities that are defined as:
public class A {
public B ClassB { get; set; }
// Bunch of code
}
public class B {
// Bunch of code
}
When I create a new instance of class A, assign it a new instance of B and insert A into the DataContext, the instance of B is also inserted into the DataC...
I am often comparing data in tables in different databases. These databases do NOT have the same schema. In TSQL, I can can reference them with the DB>user>table structure (DB1.dbo.Stores, DB2.dbo.OtherPlaces) to pull the data for comparison. I like the idea of LinqPad quite a bit, but I just can't seem to easily pull data from two d...
I have a table ContentHistory in a SQL Server 2008 database with a column Content of data type xml, NOT NULL. This column stores complete XML documents (an Intersection root node containing one or more Article nodes:
<InterSection>
<Article>
<ID>1</<ID>
...other nodes/data
</Article>
<Article>
<ID>2<...
I am new to linq to sql
I wrote this function:
public ICollection<ICustomer> GetAll()
{
DataClasses1DataContext context = new DataClasses1DataContext();
var customers = from customer in context.Customers select customer;
return customers.ToList().Cast<ICustomer>().ToList();
}
But it always return list of null values.
The...
Can I optimized the following query in any way:
The goal is to try to find clients of type 4 that also exists as type2 based on their VAT and Email. A client can have one or more clientusers.
(I have all the appropriate indexes set, I promise)
from e in Clients.Where(h => h.ClientTypeId==4)
join u in ClientUsers on e.Id equals u.Clie...
I have two Linq2SQL objects, Order and OrderLine.
An Order contains multiple OrderLines.
I created a constructor Order(Reservation reservation). The idea is that this constructor generates a new order and the orderlines that it should contain.
I have this code:
public Order(Reservation reservation) {
this.date = DateTime.Now;
...
I have made myself an ExpressionBuilder class that helps me put together expressions that can be used as a predicate when doing Linq to Sql queries. It has worked great. However, I just discovered Expressions can only be used to filter on Tables, and not on EntitySets??Why on earth is this the case?
For example if I have Company and an ...
I'm having a trouble getting a linq to sql query and was wondering if someone could help. I have these tables: 'Orders', 'OrderProducts', 'Products' and 'Users'. I want to get a breakdown of the count of how many products (contained in 'OrderProducts' by ProductID) each 'User' has ordered. The User's UserID is contained in the 'Orders...
Here's a little experiment I did:
MyClass obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single();
Console.WriteLine(obj.MyProperty); // output = "initial"
Console.WriteLine("Waiting..."); // put a breakpoint after this line
obj = null;
obj = dataContext.GetTable<MyClass>().Where(x => x.ID = 1).Single(); // same as before, b...
I am spending a good amount of time trying to figure out why Linq2Sql is changing my SQL query. It is rather difficult to explain, and I cant find any reason why this is happening. The low down is it appears that adding multiple contains around an IQueryable seems to overwrite each previous IQueryable Expression. Let me try and explain...
Help me with this algorithm please.
var companies = companyrepository.GetAll().OrderBy(sidx + " " + sord).Skip(pageIndex * pageSize).Take(pageSize);
string where = "";
if (op == "eq")
where = field + "=" + data;
else if (op == "cn")
where = field + " LIKE '%"+data+"%'"; ///here lies my problem
companies = companies.Where(where);
...
Hi.
So I want to retrieve data using stored procedures. Preferably via Linq2SQL.
So I can do something like this (example):
var productHistory = dbname.StoredProcedureMethod(value);
foreach(var product in productHistory)
{
//stuff
}
This is something I'd like to be able to do in Visual Studio 2008 in .Net 3.5.
It is possible wit...
Visual studio is yelling at me, in the database it is a float, and in my class it is a double. Why can't I assign it and why does it think it's a 'double?' ?
LINE THREE BELOW
Confirmation confirm = new Confirmation();
confirm.order = theOrder;
confirm.totalPrice = theOrder.BillingAmount;
HERE IS Confirmation DEF
pu...
So I load up an object like...
MyObject object = new MyObject();
object = objectRepository.getObjectByID(id);
object.lastLoaded = DateTime.Now();
...
//NOW WHAT????
I know there is a .Save() but does that update the current one or is that only used for creating new ones?
...