How do I get the trace string for a query like this:
var product = _context.Products.Where( p => p.Category == "Windows" )
.SingleOrDefault();
// I can't do this since product is not an ObjectQuery instance
// product.ToTraceString();
...
Let's say you have the following tables:
Friend
------
Id int not null (primary key)
Name nvarchar(50) not null
Address
-------
Id int not null (primary key)
FriendId int not null (links to Friend.Id)
City nvarchar(50) null
Country nvarchar(50) not null
Using Entity Framework 4, I am issuing an ObjectContext.ExecuteStoreCommand call ...
I'm using EF4 to call a stored procedure which returns the results of a SELECT statement at the end of the SP. However, some of the column names in the returned results contain underscore chars, or spaces, which prevents me from mapping them to a complex type. How can I retrieve the results of the SP from EF?
...
I have not hardly touched EF4, but I've used Linq to sql quite a lot. I would like to start into one of the EF templates but I have no idea what situations make sense for each or what their intent was.
I have the following possibilities:
Data templates
ADO.NET Entity Data Model
Service-based Database (is this even related to EF?
Cod...
I have a 3 tiered project.
1) Project.Data (EDMX file)
2) Project.Model (POCO's)
3) Project.Console (Console app)
I have added the connection string into the Project.Console.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="ProjectEntities" connectionString="metadata=res://*/Project.c...
It feels a little wrong to me to be doing Validation in your context which is your data layer. For the data layer to have a dependency on validation seems a little backwards. It makes more sense to me for validation to be done in business logic and once the validation is complete then persist the changes. The data layer should be able to...
I am using EF4 code first and want to generate a composite key which is made of a class property and foreign key. I have two classes: Order and Company. The Order class holds a reference but this will not necessarily be unique between companies. So I intend to use a composite key made up of Reference and Company.CompanyId.
I have tried ...
I'm trying to run a no tracking query on my entities so that I can update them outside of the context. However, when the no tracking is not working and I get an exception stating
"The ObjectContext instance has been disposed and can no longer be used for operations that require a connection."
This exception is thrown by a property wh...
One of my Entity Framework Models contains a MS-SQL View. The View is called User and contains various properties for users.
When I right click on the model and select Update Model from Database, I get the following error:
"An exception of type 'System.InvalidOperationException' occurred while attempting to update from the database. The...
I commented out the line of code that enables lazy loading from all the ctor overloads for my ObjectContext class, yet when I iterate over a navigational property, the iteration is successful. Why?
Here's the relevant bits of code.
public MyExpensesEntities() :
base("name=MyExpensesEntities", "MyExpensesEntities")...
I have a sizable legacy MS SQL database where foreign key relationships were never implemented.
Is it possible to implement "logical" foreign keys between entities in Entity Framework 4 without there being actual foreign key relationships present in the database?
...
I want to show a list of game reviews for editing. This is simple to do with VS' built-in scaffolding, but I'm running into issues with handling an entity's associated EntityCollections. My controller method is currently:
public ActionResult ShowReviews()
{
var reviews = _siteDB.Games.Include("Genre").Include("Platforms").Include(...
I know the entity frame work does not allow you to generate a model from a database using non primary unique keys as a Foreign Key association. Can I modify the EDMX manually? If so, can someone provide me an example or reference? If not, are there any other possibilities?
Easiest Example:
Here is the DDL for the tables. You will no...
Hi,
I have a small custom object defined as:
public class TimeSeriesDefinition
{
public int classID;
public DateTime startTime;
public DateTime endTime;
}
I'm passing a List classIDs, a List startTimes, and a List endTimes into an RIA Domain Service function. As a matter of organization, I was grouping these values into...
I'm using EF 4.0 and was able to create self referencing many to many relationship. Person and family members. What I also want is to add additional attribute like 'mother', 'brother', 'sister' for each relationship. At the database level, this model generates two tables. Person and PersonRelationship. PersonRelationship table has person...
Short version:
Starting with a List of entities and needing all dependent entities through an association, is there a way to use the corresponding navigation-propertiy to load all child-entities with one db-round-trip? Ie. generate a single WHERE fkId IN (...) statement via navigation property?
Long version:
I am generating a report fro...
I am using the POCO support for entity framework v4. I would like to get the Type of the POCO class that is mapped to that entity. For example you can get ObjectStateEntry from the ObjectStateManager. That entry then has a reference to the entity. The Entity is of type object so it is useless until you cast it.
This is fine if you know...
I want to do paging outside of my Repository, but the Repository returns IList. Since I don't want to pull data unnecessarily, and don't want to create specific Paging methods in my Repositories, Is there any way to filter records by page in the Where extension method?
I want to do something like:
var myRecords = ProductRepo.Get( p =>...
I use Entity Framework 4.
How can I perform a Generic Where Lambda Clause.?
I Have many Entity that need the same Where Query.
public Func<SupplierTypeText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<ProductText, bool> GetLmbLang()
{
return (p => p.LangID == 1);
}
public Func<CategoryText, bool> GetLmbL...
Is .Skip().Take() the only way to get paging in Entity Framework? Is there some way to select the row number in the output so I could use Where( p => p.row > 9 && p.row <21)?
select top 100 ROW_NUMBER() over (order by ID) as row, *
from myTable
I would think the ROW_Number() field must exist in the generated SQL for it to know what ...