I have a many-to-one relationship that users can edit via checkboxes. PK of Foo is ID, and fid contains the id from the checkbox.
I'm checking to see if an element exists with:
Foo ent;
try
{
ent = ctx.Foo.First(f => f.ID == fid);
}
catch (System.InvalidOperationException ioe)
{
ent = new Foo();
}
It seems to me that I should be...
I have 2 tables (Users and Roles) they are mapped as Many-to-Many in relational db. When I imported to Entity Data Content, they are still staying as the same relationship.
Since they are mapped as Many-To-Many in Entity, I can access
Users.RoleCollection
or
Roles.UserCollection
However, when I execute this LINQ query, I got "LINQ...
Hello All,
I want to write a LINQ to Entity query which does order by ascending or descending based on input parameter, Is there any way for that.
Following is the my code. Please suggest.
public List<Hosters_HostingProviderDetail> GetPendingApproval(SortOrder sortOrder)
{
List<Hosters_HostingProviderDetail> returnList ...
Order by descending is not working on LINQ to Entity
In the following Query In place of ascending If I keep descending it is not working. Please help me out
var hosters =
from e in context.Hosters_HostingProviderDetail
where e.ActiveStatusID == pendingStateId
orderby e.HostingProviderName ascending
select e;
return host...
I have four tables:
Users PrivilegeGroups rdPrivileges LinkPrivilege
----------- ---------------- --------------- ---------------
userId(pk) privilegeGroupId(pk) privilegeId(pk) privilegeId(pk, fk)
privilegeGroupId(fk) name code priv...
I have following code to delete an user from database:
try
{
var user = from u in db.Users
where u.Username == username
select u;
if (user.Count() > 0)
{
db.DeleteObject(user.First());
db.SaveChanges(...
Are the following two statements the same?
Users user = db.Users.First(u => (u.Username == username));
and
var user = from u in db.Users
where u.Username == username
select u;
Users aUser = user.First();
...
I was told in L2S, the code for update and insert are the same,
db.InsertOnSubmit(row);
db.SubmitChanges();
and L2S will check to see if it is a insert or update and act approprately in the background.
Is that true?
How about L2E? I tested, looks like in L2E it is not like that. Maybe I did something wrong.
...
I am trying to figure out how to do a series of queries to get the updates, deletes and inserts segregated into their own calls. I have 2 tables, one in each of 2 databases. One is a Read Only feeds database and the other is the T-SQL R/W Production source. There are a few key columns in common between the two.
What I am doing to set...
Hi,
I have a table in SQL database:
ID Data Value
1 1 0.1
1 2 0.4
2 10 0.3
2 11 0.2
3 10 0.5
3 11 0.6
For each unique value in Data, I want to filter out the row with the largest ID. For example: In the table above, I want to filter out the third and fourth row because the fifth and sixth rows...
Hello, I have two tables that are connected via a join table in a many-to-many relationship in the Entity Framework. I need to add a composite primary key in the join table for the two columns that are related to the joined tables via standard foreign keys but I'm sure how to do that.
...
is there a way to write this same SQL atomic instruction using Entities and LinQ?
IF EXISTS (SELECT * FROM MyTable WHERE ID = @Id)
UPDATE MyTable SET name = @name
ELSE
INSERT INTO MyTable (@Id, @name)
or do you need to call a stored procedure from within the EF?
...
Hello there,
I have a little problem which i can't solve.
I want to use an SQL-In-Statement in Linq. I've read in this Forum and in other Forums that I have to use the .Contains (with reverse-thinking-notation :-)).
As input i have a List of Guids. I first copied them into an array and then did something like that :
datatoget = (from p...
Hello guys,
I have a requirement of updating set of N records into the db table at a time. How can I achieve it in LINQ to Entity(.edmx file). If I update them using conventional procedure in LINQ To Entiy, It wont be good practice, How can I achieve this.
...
Is their a way to use linq to SQL/Entities 4.0 to work with the hierarchy datatype?
...
I've got a vertical market Dot Net Framework 1.1 C#/WinForms/SQL Server 2000 application. Currently it uses ADO.Net and Microsoft's SQLHelper for CRUD operations.
I've successfully converted it to Dot Net Framework 4 C#/WinForms/ SQL Server 2008. What I'd like to do is also offer my customers the OPTION to use SQL Azure as a backen...
Sorry for the vague title but I really didn't know what title to give to this problem:
I have the following result set:
ID Field FieldValue Culture
1 Color Groen nl-NL
2 Taste Kip nl-NL
3 Color Green en-GB
4 Taste Chicken en-GB
5 Color Green en
6 Taste Chicken ...
I have a couple of tables where there are one to many relationships. Let's say I have a Country table, a State table with a FK to Country, and a City table with a FK to State.
I'd like to be able to create a count of all Cities for a given country, and also a count of cities based on a filter - something like:
foreach( var country in ...
This works:
(from o in Entities.WorkOrderSet
select o)
.Where(MyCustomMethod);
This does not:
(from o in Entities.WorkOrderSet
select o)
.Where(o => MyCustomMethod(o));
([Edit] Even without new, it doesn't work)
I understand why the second doesn't work - but why in the world does the first work!? Shouldn't I get a "LINQ-to-Enti...
I read other posts on similar problem on using SingleOfDefault on Linq-To-Entity, some suggested using "First()" and some others suggested using "Extension" method to implement the Single().
This code throws exception:
Movie movie = (from a in movies
where a.MovieID == '12345'
select a).SingleOrDefaul...