I'm new to the Entities Framework, and am just starting to play around with it in my free time. One of the major questions I have is regarding how to handle ObjectContexts.
Which is generally preferred/recommended of these:
This
public class DataAccess{
MyDbContext m_Context;
public DataAccess(){
m_Context = new MyDb...
When you run Linq to Sql or Linq to Entites to get a list of records it runs query to select all fields from a table. Is it an efficient solution. Lets say: I run this LINQ
dim lstCustomers = from c in db.Customers select c
it run query to get all fields from a table whether i need all fields or not. I am using asp.net with MVC so sho...
When using Linq to Entities, is it still necessary to abstract database access using a separate Data Layer, or is it acceptable (or even recommended) to make Linq queries directly from code-behind (Since the Get, Add, Update, and Delete functionality is already built into the Entity Framework)?
...
The question is in the title.
...
I'm new to "Linq to Entities" and i'm getting this error while passing data to the View (ASP.net MVC). I would like to know why is this happening and how can i fix that?
...
Having two classes like Blog and Post, in Entity Framework (and LINQ-to-Entities), how can you get the blogs with the posts sorted by date. I was getting the blogs with the posts this way:
from blog in db.BlogSet.Include("Posts") select blog
and now I'm forced to do this:
public class BlogAndPosts {
public Blog Blog { get; set; }...
I have list of book titles and I have to list chapters like this.
Title 1
Chapter1
Chapter2
Chapter3
Chapter4
Title 2
Chapter1
Chapter2
So, I have list inside a list. I can get list of books (and titles) but when i reference their chapters i get nothing. well, how can I do that?
<% foreach ...
Hi All,
I have a query (developing in linqpad):
DateTime currentDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DateTime previousMonth = currentDate.AddMonths(-1);
DateTime previousMonthForAveragePrices = currentDate.AddMonths(-2);
var help = from cd in CostDrivers.OfType<Commodity>()
where cd.isActive =...
Hi
I have 2 tables that have a relation ship to each other
Table A has 1 to many relationship with table B
so this make a navigation property into each.
Now I need to check a value from Table A(userName) and I need to check a value from table B(ClubId).
So in my mind it would be something like
Join the tables together
Where A.userN...
I am using entities, C# and SQL Server to create an n-tier app. I am creating some base classes common to all my DAL components. In this base class, i want to handle the connection state of the ObjectContext base class inherited by entities object.
Compiling throws the following error:
The type or namespace name 'Objects'
does n...
I would like to know what are the principal diferences between "ADO.NET Entitiy Data Model" and "Linq to SQL Classes"? What is the best choice to work with?
I couldn't find any document on the internet explaing that and everything I know is that we can use both, "almost", in the same way.
...
When I decided to use an OR/M (Entity Framework for MySQL this time) for my new project I was hoping it would save me time, but I seem to have failed it (for the second time now).
Take this simple SQL Query
SELECT * FROM POST ORDER BY addedOn DESC LIMIT 0, 50
It executes and gives me results in less than a second as it should (the ta...
Hey everyone,
I'm working on a WPF system which hooks onto an old legacy database using the Entity Framework. We hook onto a backup of the live data when debugging and an empty database to run tests against. I'm receiving the following error only when trying to delete from a backup of the live data.
This code:
License license = ReadLi...
Ok, so let me explain a little of what I am trying to do.
I have a table called WebsitePage that contains all of the pages on my site with some information about them. Then, I have a Customer table for all of my customers. Then I have another table called CustomerWebsitePage that stores customer values for some of the columns in the Web...
I am writing an app using .NET, C#, LINQ to entities and SQL Server 2008.
I would like to pick a row randomly from a table. Is there a way to achieve this using the LINQ queries. One approach would be to get a list of rows from the table and then pick one of them randomly, which is very straight forward.
Just curious, if there is a way...
As I read the a similar question about searching SQL I realized I am very curious on how to do the same thing in Linq.
Assume a DB Table with the fields "Title", "Tags" (comma separated) and "Body" (HTML) that has been connected to a Linq2[Entities|Sql] How would you go about searching for a string across those fields.
Yes, I could b...
Example code taken from another SO Question
var test = context.Tests
.Include("Question.QuestionLocale")
.FirstOrDefault();
If your DB schema needed to change for some reason, how could a developer possibly deal with hard-coded values used in a method that takes a string parameter (Include method us...
Aknittel
NewSellerID is the result of a lookup on tblSellers. These tables (tblSellerListings and tblSellers) are not "officially" joined with a foreign key relationship, either in the model or in the database, but I want some referential integrity maintained for the future. So my issue remains. Why do I get the exception ({"An item with...
Is there any way in LINQ to do an OrderBy and then do a ThenBy with the ThenBy using the children of the parent object to do the secondary ordering?
_repository.GetActiveDepartmentGroupsWithDepartments().OrderBy(c => c.DepartmentGroupName).ThenBy(c => c.Departments.OrderBy(d => d.DepartmentName))
In the above case, c.Departments is an...
Hi All,
How can i create a query that will return a single entity along with a collection, and have the collection sorted? i don't care if it's two calls to the DB.. i just need the end result to be an Entity type and not an anonymous type:
var
category = context.Categories.Where(c => c.categoryID == categoryID).Select(c => new { c, p...