I'm pulling some data from a table using LINQ 2 SQL...one of the pieces of data is a value that represents an enumation in my application code.
What is the simplest way to make a comparison between the data returned in LINQ objects and the enumeration in the application code. So for example
enum SomeEnum
{
First
Second
}
then in...
I'm working with a 14-year old schema where a parent table (P) contains a type (8 possibilities) and location (3 possibilities) field that together point to one of twenty-four specific tables (A1, A2, A3, B1, B2, B3...), all with identical schemas for their type.
I would like to create a generic way to access the specific tables but can...
if you have something like(just an example don't worry)
var result = from n in mytable select n;
var last = n.LastOrDefault;
var secondresult = n.FirstOrDefault;
var Thirdresult = secondresult.FirstOrDefault;
var Finalresult = Thirdresult.FirstOrDefault;
is this will query the database 5 times?
...
Joining two tables in LinQ and VB.
Hello,
I have a listview and I am binding based on a linq query. It it is just one table it is working fine.
If I join the 2nd table it is not displaying any records
How do I add join two tables in this linq query?
I have commented the join query as it is not working
Dim db As New SettlementsDataCon...
I've got a very simple data structure. I'm using SQLExpress with Linq2SQL and vb.net
**ParentClass**
parentId
name
**ChildClass**
childId
name
parentId (foreign key to parent table)
The dbml reflects these two classes, and has a oneToMany association.
So far, so good.
In my code, i'm trying to get the value as follows
Dim count...
Hi,
I’m having trouble with some dbml generated classes that don’t to resolve down to efficient SQL. Imagine I have an Accounts table and a Transactions table where each transaction is associated with a particular account. I load all this into dbml and out pops an Account class and a Transaction class. The Account class has an Entity...
Ok, I found this, which will allow me to do this:
public IList<Item> GetItems(string orderbyColumn)
{
return _repository.GetItems().OrderBy(orderByColumn).ToList();
}
Is this the best way to do "dynamic" ordering? I want to be able to pass the column name as a string (and the sort direction) to my Service, and have it order the c...
I'm looking for a good approach for calculating and caching periodic opening account balances using SQL.
I know I can use SQL to sum up a bunch of transactions from start of time to the start of the period in question, but I'm more interested in whether its worth caching those calculated balances (at various points in time) in another ...
Hello, Guys
Is it possible that I can add Table<T> dynamiclly to an exisitng DataContext Insance in LinqToSQL?
Here is my case:
I have several classsed which are using [Test] attribute to declared as Table, I want to allow user to create the corresponding SQL Server tables during run-time. I understand that If I inherit the DataC...
I've got a set of DB objects sitting in an EntitySet on my main object definition. This handles additions and updates fine, but I found the removing items from the list didn't result in the database records being deleted, so I had to create a method in the data repository object to delete the records as the data object doesn't have acce...
IQueryable<SomeType> result = (from x in Context.XXX select x);
now what I need to do is the following (written pseudo code, I need actual code):
foreach(var i in items)
{
// Where the object "i" has 2 properties
// 1) i.Operator (values of which can be AND or OR)
// 2) i.SomeID (values of which can be 1 .. 10)
// I need to b...
I have a WinForm App that uses multiple DataGridViews. The DGV's used to be bound to DataTables in the old SProc's DAL. As I was converting the SProcs to LINQ I originally was following suite but I am wondering if that is the "best" way.
This is a sample of what I am doing.
internal static CmoDataContext context = new CmoData...
For other reasons, i've had to create my own property in an Entity in the ORM, which has is a type of another entity (had issues with associations so did it this way instead).
The problem is that whenever I make a change to that property, it isn't being flagged as a change so I cannot call SubmitChanges on it.
So basically my question ...
Basically I want to be able to recreate this query in Linq
SELECT *
FROM Customers
LEFT JOIN Orders LastOrder
ON LastOrder.CustomerId = Customers.CustomerId
&& LastOrder.CreatedOn = (Select MAX(CreatedOn) FROM Orders WHERE CustomerId = Customers.CustomerId)
LEFT JOIN OrderStatus
ON OrderStatus.OrderStatusId = LastOrder.OrderStatusId...
I have the below LINQ Query that I would like to suppliment with the Nurse Names. Unfortunately these are stored in a seperate DB and thus a seperate DataContext.
How would I go about calling a method in my aspnetdbcontext from this query, which uses cmodatacontext?
This is the method in aspnetdb to get a nurse's name:
internal s...
Often I need to combine data from multiple tables and display the result in a GridView control.
I can write a Linq query inline in the Page_load event, return an anonymous type that combines all the fields that I need, and databind the result to the GridView control.
Problem: I use 'helper methods' as described by Scott Guthrie on hi...
I have a GridView that is using a LinqDataSource which is tied to a table in my database. This table of mine has a int foreign key. In my presentation layer, using TemplateField in Gridview, i hide the foreign key value and make another call to the database to show the name of it's associated name so it's more readable for the user.
Ho...
Hi ALL,
I have data like this
productid cost
prant 6.70
prant 0
prant 7.0
gant 8.7
gant 0.1
gant 4.5
how can i flatten them into one result as "prant 13.70 gant 13.3" in Linq To sql
My linq query gives me two rows
Results:
prant 13.7
gant 13.3
Query:
from c in test
group new {c}
by new...
var candidates = (from l in db.GetLeads(lat, lon, role, radius + 10)
orderby l.Distance
select l);
return (List<CandidateResult>)candidates;
...
I'm using LINQ to SQL like:
var b =
from s in context.data
select new
{
id = s.id,
name = s.name
myEnumerable = s.OneToMany
};
Where myEnumerable is of type IEnumberable<T> and I want to now get a subset of b based upon properties of the individual items of myEnumerable. For example, say <T> ...