var items = from c in contacts
select new ListItem
{
Value = c.ContactId, //Cannot implicitly convert type 'int' (ContactId) to 'string' (Value).
Text = c.Name
};
var items = from c in contacts
select new ListItem
{
Value = c.Conta...
Crazy question...however, I want the sum of all the rows in a table for a column (without using the group by clause)
Example:
Table = Survey
Columns = Answer1, Answer2, Answer3
1 1 1
4 3 5
3 3 2
I want the sums for each column.
Final results should look like:
Ans...
I am trying to perform a query using linq to entities to that an entity/table doesn't contain the same values before I update it.
The structure of the database is as follows:
Users User_IPAddresses IPAddresses
----- ---------------- -----------
UserID >------ UserID ------< IPAddr...
I have an entity that has one child and I need to update it, but, in the TryUpdateModel method, it does not accept an strong typed object (accepts only a FormCollection), and when I try to update it, I get the following error.
{"A relationship is being added or deleted from an AssociationSet 'FK__SG_Usuari__ID_Si__534D60F1'. With cardi...
I am trying to get the first item in the database that has the a given 'UserGuid', but the 'First' extension method is throwing the following exception: System.InvalidOperationException: Sequence contains no elements
Here are some examples of what works and what does not:
// Works
var FoundUser1 = MyEntities.Users.First();
// Works
va...
It seems there are two ways to build queries -- either using query expressions:
IEnumerable<Customer> result =
from customer in customers
where customer.FirstName == "Donna"
select customer;
or using extension methods:
IEnumerable<Customer> result =
...
Please help.
I am trying to figure out how to use DATE or DATETIME for comparison in a linq query.
Example:
If I wanted all Employee names for those who started before today, I would do something like this in SQL:
SQL ------
Select
EmployeeNameColumn
From
EmployeeTable
WHERE StartDateColumn.Date <= GETDATE() //Today
SQL ------
But w...
Hi,
I am at a loss with the following query, which is peanuts in plain T-SQL.
We have three physical tables:
Band (PK=BandId)
MusicStyle (PK=MuicStyleId)
BandMusicStyle (PK=BandId+MusicStyleId, FK=BandId, MusicStyleId)
Now what I'm trying to do is get a list of MusicStyles that are linked to a Band which contains a certain searchs...
I am looking for a way to see what the sql is that my L2E code has generated for debugging purposes.
I have read a blogpost by Scott G. on a visualizer for Linq2SQL but I can't get it to work for L2E.
Do you know of some way to visualize the generated SQL from L2E?
I am using Visual Studio 2008 SP1 Professional.
...
Hey
I have a problem with my LINQ to Entity model many to mant relation. I am new to both C# and LINQ, so bear with me.
I have a model containing pictures and tags, where each picture can have many tags, and each tag can be on many pictures. In the db there is a normal relation table, but in the object model I see it as picture.tags (a...
I have a EF class with a connection to a sql server database "mydb", I like to update data on another database (suppose mydb2.dbo.anothertable) on same server, Can I create a entity that is related to this "another" database using the same connection?
(excuse me for my grammar errors, I speak in spanish)
...
I am using multiple layer project where the DataModel hosts the ADo.NET Entity model and DataAccess layer does the validation.
However everytime I get a error like this
The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
I have tried connec...
Hello,
I am looking to develop a website for a news channel.
So, Obviously its gonna receive a lot of hits daily and will be updated a lot on daily basis..
I have experience in ASP.Net and SQL Server..
These are the technologies i am considering to work with. Please help me choose the right method considering the amount of load it w...
In a LINQ to entities expression like this:
var vote = (from vote in db.Vote where
vote.Voter.Id == user.Id
select v).FirstOrDefault();
how do you you add a DefaultIfEmpty so that when there's no vote I'd get a default value?
...
I asked this question earlier but I think I phrased it incorrectly, so here is attempt number two. I have the following code:
public User EditUser(User userToEdit)
{
//userToEdit contains values for eagerly loaded contacts entity
User originalUser = (from u in _entities.UserSet.Include("contacts")
...
Hello,
I have to build a website for a news channel..
Please help me decide which technology to use for data operations?
1) Linq to Entities
2) Linq to SQL
3) Fluent NHibernate
4) ADO.Net
Website will be based on ASP.Net MVC and C#.
Main Issues:
1) Should be easy to maintain and scale.
2) Good Performance
Please express your vie...
I'd like to merge the following Expression:
// example class
class Order
{
List<OrderLine> Lines
}
class OrderLine { }
Expression<Func<Order, List<OrderLine>>> selectOrderLines = o => o.Lines;
Expression<Func<List<OrderLine>, Boolean>> validateOrderLines = lines => lines.Count > 0;
// now combine those to
Expression<Func<Or...
I have:
select distinct to_date(to_char(i.fe_stax, 'DD/MM/YYYY'), 'DD/MM/YYYY') FechaProg, a.id_ciud, t.no_ciud from itinerario i
where to_date(to_char(i.fe_stax, 'DD/MM/YYYY'), 'DD/MM/YYYY') is not null
I want something like this?
var tmp = (from itin in db.ITINERARIO
where itin.FE_STAX != null
...
I having a weird problem with Entity Framework with MySql database.
Here's the code that I've got.
public class testbase
{
private testEntities db = new testEntities();
public IQueryable<post> GetRecords()
{
return db.record;
}
}
Here record is a table in my database and this could should return all the rows ...
Hi,
Whenever I read an article on linq to entities, I sounds like I should embed my business logic in the generated entity-classes.
This would means that the "user" of the business-objects (controller, service-layer, ...) would have to know about the datacontext-object that's needed to use linq.
It would also mean that the DAL-logic a...