entity-framework-4.1

how do I sort a collection with child property?

*爱你&永不变心* 提交于 2019-11-29 04:48:10
I should sort parent based on a field of child. sample code; IQueryable<Parent> data = context.Parents.Include(o=>o.Children); //Child has a member (string) Name. question: how can I sort Parent by Children Names. Your question is somewhat confusing, since first of all, it is tagged both with Entity Framework and LINQ-to-SQL. Which ORM are your actually using? Secondly, and more to the point, you say that you want to "sort Parent by Children Names" . Which child name do you want to sort by? You do realize that you can't compare a list of names to another list of names and decide which one

Insert record in child table when parent record already exists using Entity Framework code first

天大地大妈咪最大 提交于 2019-11-29 02:28:58
I have some Parent records already inserted in the database. Now i want to add some child records. To do this I followed following steps: Retrieve the Parent(A) records Create a new child(B) record Add parent record to the Navigation property of Child. B.A = A Call SaveChanges. The problem is when i do this EF inserts a New Parent and then add the child with a foreign key pointing to new newly inserted parent instead of inserting just the child with mapping to already existing parent. I also checked the parent's primary key when saving the child and it does exists in the database. Note that i

EF 4.1 CF: CREATE DATABASE permission denied in database 'master'

偶尔善良 提交于 2019-11-29 02:06:11
Entity Framework 4.1 Code First works great with SQLEXPRESS on localhost . However, I'm now ready to connect to a regular SQL 2008 server . I created a new database "NewEfDatabase". Then changed my " ApplicationServices " connectionString in Web.config to point to my new database with integrated security. But then I get this error: " CREATE DATABASE permission denied in database 'master'. " So... a) What permissions does EF 4.1 CF need on said SQL server to do its work? b) Can I setup an empty database on SQL 2008 for EF 4.1 CF, or do I have to let it do all that work for me? (I'm not sure my

Command Timeout with Entity Framework 4.1 Code First

依然范特西╮ 提交于 2019-11-29 01:01:14
How can I set the command timeout of a DbContext? I found this solution after another Google search. You can access the ObjectContext for a DbContext by casting this to an IObjectContextAdapter. From http://social.msdn.microsoft.com/Forums/en-ZA/adodotnetentityframework/thread/6fe91a64-0208-4ab8-8667-d061af340994 : public class MyContext : DbContext { public MyContext () : base(ContextHelper.CreateConnection("my connection string"), true) { ((IObjectContextAdapter)this).ObjectContext.CommandTimeout = 300; } } A better solution to this for later versions of Entity Framework is to use the

Wait! which config file? (Entity Framework Connection String)

限于喜欢 提交于 2019-11-29 00:24:10
问题 So, I created my entity model in a separate class library. I had to add the connection string to the app.config file of that class library. Then I added a ref for that project in my web application. I added the same connection string in the web.config of my web application thinking this is where Entity Framework will be reading the connection string from. Everything was fine up until I deployed my web app. When I deployed I change the connection string in the web.config (not app.config of the

Multiple DbContexts in N-Tier Application

你。 提交于 2019-11-29 00:06:37
I'm creating my first N-Tier MVC application and I've run into a road block with how to manage multiple DbContexts with my database first approach. I have the following layers Presentation Service (WCF) Business Data Access I don't want an entity framework reference in my service layer but I don't see how to create an Interface or something to manage two contexts. I have it working with a single context warpped in a IDatabaseFactory but I can't seem to find an approach to manage two. Below is my UnitOfWork that is created in my Service ctor but every way I look at it I'm still tied to the

The type or namespace name 'Entity' does not exist in the namespace 'System.Data'

瘦欲@ 提交于 2019-11-28 23:32:05
问题 I'm using WS class and it gave me error when I run the application: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' I have a reference to the System.Data; and to System.Data.Entity; But no changes. I keep getting the error. I have also in the web.config the line: <compilation debug ="true" targetFramework="4.0"/> 回答1: Right-click on the Solution from the Visual Studio Solution Explorer click the Manage Nuget packages for solution and install the

SQL “not in” syntax for Entity Framework 4.1

会有一股神秘感。 提交于 2019-11-28 22:54:16
I have a simple issue with Entity Framework syntax for the "not in" SQL equivalent. Essentially, I want to convert the following SQL syntax into Entity Framework syntax: select ID from dbo.List where ID not in (list of IDs) Here is a method that I use for looking up a single record: public static List GetLists(int id) { using (dbInstance db = new dbInstance()) { return db.Lists.Where(m => m.ID == id); } } Here is a pseudo-method that I want to use for this: public static List<List> GetLists(List<int> listIDs) { using (dbInstance db = new dbInstance()) { return db.Lists.Where(**** What Goes

Entity Framework: Tracking changes to FK associations

偶尔善良 提交于 2019-11-28 21:59:16
I'm overriding SaveChanges on my DbContext in order to implement an audit log. Working with many-to-many relationships or independent associations is relatively easy as EF creates ObjectStateEntries for any changes to those kinds of relationships. I am using foreign key associations, and when a relationship between entities changes all you get is an ObjectStateEnty that says for example entity "Title" has "PublisherID" property changed. To a human this is obviously a foreign key in Title entity, but how do I determine this in runtime? Is there a way to translate this change to a "PublisherID"

Loading Nested Entities / Collections with Entity Framework

你说的曾经没有我的故事 提交于 2019-11-28 21:21:12
I am trying to Eagerly load all the related entities or collection of Entity in one call. My Entities Looks like: Class Person { public virtual long Id { get; set; } public virtual string FirstName { get; set; } public virtual string LastName { get; set; } } Class Employee { public virtual long Id { get; set; } public DateTime AppointmentDate { get; set; } public virtual ICollection<EmployeeTitle> Titles { get; set; } public virtual Person Person { get; set; } } Class EmployeeTitle { public virtual long Id { get; set; } public virtual bool IsCurrent { get; set; } public virtual Title Title {