Hi,
I have SQL 2008 server with tables Employee, Phone and Email where Employee is in a one-to-many relation with Phone and Email (So employee can have many phone numbers and emails).
Now I want to query employee with all phones and emails:
var query = (from e in db.Employee
select new EmployeeDTO
{
...
I'm trying to make a repository class that has a method to order the results based upon a "sort" parameter. I need to pass it as a parameter since I'm trying to be very strict that my repository doesn't return IQueryable and only returns List. The problem is that I have no idea how to make it so that it meets the following requirements:
...
I am really struggling to insert some data into 2 database tables.
I am using Linq over WCF Data Services using Entity Framework 4.
The 2 tables look like this:
CREATE TABLE [dbo].[Accounts] (
[Id] int IDENTITY(1,1) NOT NULL,
[Email] nvarchar(max) NOT NULL,
[Password] nvarchar(max) NOT NULL
);
CREATE TABLE [dbo].[Employ...
I've just recently started using LINQ on a daily basis. I've read quite a lot about L2E queries should be compiled to improve performance using the following:
CompiledQuery.Compile(query);
Using LINQ-To-Entities 4.0 I ran a query 10 times uncompiled and then compiled and yielded the following results in seconds:
// Sample Query
from ...
I'm writing an ASP.NET MVC 2 application that uses Entity Framework 4 and WCF Data Services.
I want to manipulate the many-to-many (composite key) relationship between Duties and Workers based on the state of some checkboxes.
A Worker may have zero or more duties. A Duty may have zero or more workers.
This code is from one of my contr...
I have an array of Person pocos, populated below. I'm trying display them alphabetically by Province, then by LastName within the Province. I'm using grouping and I can get the Provinces sorted fine, just not sure how to order the people within the province group.
This code:
Person[] people = new Person[]
{
new Person() { FirstNam...
I have an application that does the following:
one component looks for changes in a database
For every change, a row is added to a table storing change alert information
Another component looks for alerts
For each alert, an alert form pops up
Previously, I had my code only show one alert at a time, and things worked just fine. Now, I...
Hi, I'm pretty new to databases and sql. I have a problem where I have two tables which both contain a foreign key to the primary key of the other. My problem is I have a large number of elements which can have multiple names in different languages, but MUST have a single primary name/language.
Firstly, I want to know if this is possib...
Can anyone tell me how to best possible way to convert the following code to LINQ:
static int MyMethod(MyClass my, bool b)
{
int cnt = 0;
foreach(SomeClass cls in my.SomeMethod()
{
cnt = cnt + cls.length;
}
if(b == true)
{
foreach(MyClass aa in my.SomeOtherMethod())
{
cnt = cnt + MyMethod(aa, true); // r...
I have some Linq to WCF DataService code that looks like this:
Account account = Account.CreateAccount(1);
Employee employee = Employee.CreateEmployee(1);
context.AddToAccounts( account );
context.AddToEmployees( employee );
employee.Account = account;
context.SetLink(employee, "Account", account);
context.SaveChanges();
This is ...
I have a table of orders made by persons:
Orders
{
Guid PersonId,
int Priority,
Guid GoodId
}
Priority is some integer number. For example:
AlenId 1 CarId
DianaId 0 HouseId
AlenId 3 FoodId
DianaId 2 FlowerId
I want to retrieve highest priority orders for each person:
AlenId 1 CarId
DianaId 0 HouseId
...
public List<string> TagNameList (int objectId)
{
List<string> tagNameList = db.Tags.Where(ob => ob.Id == objectId).ToList();
}
db.Tags.Where(ob => ob.Id == objectId).ToList();
I'm going into the db context in the Tags and i select all the tags that have a set objectId via a navigation property i have setup through an ObjectTags...
Hi if i create some instance of class products and then take one product from database using LINQ can i map result to this instance?
products produkt1 = new products();
var oneProduct= (from p in db.products where p.number == 640 select p)
.FirstOrDefault();
produkt1 = oneProduct;
but of course it doesn't work , how sh...
I have a list of Customer objects, which I've grouped on Country.
var query =
from c in ctx.Customers group c by c.Country
...
query is now an enumeration of groups (IQueryable<IGrouping<string, Customer>>), where each item of thie enumeration defines a group (IGrouping<string, Customer>).
I understand that IGrouping is: the...
Edit: Both the answers below work. My problem was due to using the NHibernate LINQ provider
like this:
from parks in Session.Linq<Park>()
instead of like this:
from parks in Session.Linq<Park().AsEnumerable()
I have a class called Park which has an of Amenities. I want to create a LINQ query that returns all Park objects which c...
I have a list of objects, each with a bool ShouldRun() method on them.
I am currently iterating over the list of objects, and checking ShouldRun() on each object, and calling Run() on the first one to return true
foreach (child in Children)
{
if (child.ShouldRun())
{
child.Run();
break;
}
}
I would like to do t...
Hi,
Here's the situation:
I'm attempting to get a collection of all types in my assembly that implement a specific generic interface along with the generic type parameters used. I have managed to put together a Linq query to perform this but it seems awfully redunant.
I've read up on let and joins but couldn't see how to I'd use them t...
I am trying to optimize my database now using Database Engine Tuning Advisor, and the problem I am facing is that my SQL Profiler trace shows tons of queries performed using sp_executesql - and the advisor fails to process those. It seems like these queries come from LINQ-to-Entities I am using, so just curious if there is any way to mak...
That's a horrible title, sorry.
Here's the scenario:
WCF Service uses LINQ to get data from a SQL database. Service is deployed on 4 (nearly) identical servers running under IIS. All are talking to the same SQL server on a separate machine.
3 of the 4 servers are working great.
On the 4th server we're getting this
A network-rel...
i try to learn transaction scope. Everything looks good. i try to control transaction is running i add 500 char in NAME value (Name nvarchar(50) normally). While My formApplication not running (it is normal), i try to open a table table is empty. Stop running my app form . i can see values of Tables. WHY?
using (var ctx = new DataClass...