Quantcast
Channel: Entity Framework
Viewing all 10318 articles
Browse latest View live

Commented Unassigned: BUG: TableBuilder.PrimaryKey [1597]

$
0
0
#Migrations

When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.

Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```

generates the following DDL:

```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```

Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: Hi Ernst, I'm not able to reproduce the column naming issue. If I define the following class and context: ``` using System.Data.Entity; namespace Repro { public class MyContext : DbContext { public DbSet<MyEntity> MyEntities { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<MyEntity>() .Property(e => e.Id) .HasColumnName("intMyCustomId"); } } public class MyEntity { public int Id { get; set; } public string Name { get; set; } } } ``` Then call Add-Migration I get the following migration scaffolded: ``` namespace ConsoleApplication17.Migrations { using System; using System.Data.Entity.Migrations; public partial class Test : DbMigration { public override void Up() { CreateTable( "dbo.MyEntities", c => new { intMyCustomId = c.Int(nullable: false, identity: true), Name = c.String(), }) .PrimaryKey(t => t.intMyCustomId); } public override void Down() { DropTable("dbo.MyEntities"); } } } ``` Which in turn generates the correct SQL: ``` CREATE TABLE [dbo].[MyEntities] ( [intMyCustomId] [int] NOT NULL IDENTITY, [Name] [nvarchar](max), CONSTRAINT [PK_dbo.MyEntities] PRIMARY KEY ([intMyCustomId]) ) ``` ~Rowan

Commented Unassigned: BUG: TableBuilder.PrimaryKey [1597]

$
0
0
#Migrations

When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.

Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```

generates the following DDL:

```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```

Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: I also verified that the 'name' parameter on the column API is correctly generated when the column name isn't a valid C# identifier. For this config: ``` modelBuilder.Entity<MyEntity>() .Property(e => e.Id) .HasColumnName("my custom name"); ``` This is generated by Add-Migration: ``` CreateTable( "dbo.MyEntities", c => new { mycustomname = c.Long(name: "my custom name", nullable: false, identity: true), Name = c.String(), }) .PrimaryKey(t => t.mycustomname); ``` Which in turn generates: ``` CREATE TABLE [dbo].[MyEntities] ( [my custom name] [bigint] NOT NULL IDENTITY, [Name] [nvarchar](max), CONSTRAINT [PK_dbo.MyEntities] PRIMARY KEY ([my custom name]) ) ```

Commented Unassigned: BUG: TableBuilder.PrimaryKey [1597]

$
0
0
#Migrations

When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.

Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```

generates the following DDL:

```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```

Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: Finally I also verified that the name parameter on PrimaryKey is correctly used that the PK name in the generated script. ``` CreateTable( "dbo.MyEntities", c => new { mycustomname = c.Long(name: "my custom name", nullable: false, identity: true), Name = c.String(), }) .PrimaryKey(t => t.mycustomname, name: "MyCustomPkName"); ``` Produces this SQL: ``` CREATE TABLE [dbo].[MyEntities] ( [my custom name] [bigint] NOT NULL IDENTITY, [Name] [nvarchar](max), CONSTRAINT [MyCustomPkName] PRIMARY KEY ([my custom name]) ) ```

Closed Unassigned: BUG: TableBuilder.PrimaryKey [1597]

$
0
0
#Migrations

When specifying a custom column-name for Primary Key, it isn't used.
There are no tests covering the scenario, and so even though the API seems to support it, it isn't implemented.

Example:
```
CreateTable(
"dbo.MyTable",
c => new
{
Id = c.Long(nullable: false, identity: true, name: "intMyCustomId")
})
.PrimaryKey(t => t.Id, name: "intMyCustomId");
```

generates the following DDL:

```
CREATE TABLE [dbo].[MyTable] (
[intMyCustomId] [bigint] NOT NULL IDENTITY,
CONSTRAINT [PK_dbo.MyTable] PRIMARY KEY ([Id])
```

Which gives the following error:
> System.Data.SqlClient.SqlException (0x80131904): Column name 'Id' does not exist in the target table or view.
Comments: See previous comments

Commented Issue: Code First: [InverseProperty] and [ForeignKey] DataAnnotations not working properly. [138]

$
0
0
"Repro Steps:
See: http://stackoverflow.com/questions/10020660/why-does-ef-code-first-inverseproperty-attribute-fail-to-work-when-used-with

Actual Results:
Issue 1:EF 4.3.1 - NullReferenceException (EF 4.1 did not have this problem)
Issue 2: An extra Database Column is created for the foreign key that I am already specifying with the DataAnnotation

Expected Results:
Issue 1: No exceptions
Issue 2: A foreign key column should not be auto generated as I am explicitly stating it with a DataAnnotation."

This item was migrated from the DevDiv work item tracking system [ID=397777].

This work item originated from connect.microsoft.com. A member of the EF team at Microsoft should close the related Connect issue when closing this work item.

Comments: Confirmed that with EF 4.3.1 the following classes: ``` public class MyContext : DbContext { public DbSet<Match> Matches { get; set; } public DbSet<Player> Players { get; set; } } [Table("Matches")] public class Match { [Key] public long Id { get; set; } [ForeignKey("Player1Home")] public long? HPlayer1Id { get; set; } public virtual Player Player1Home { get; set; } } [Table("Players")] public class Player { [Key] public long Id { get; set; } [InverseProperty("Player1Home")] public virtual ICollection<Match> MatchesAsHome1 { get; set; } } ``` Incorrectly result in the following database: ``` CREATE TABLE [Matches] ( [Id] [bigint] NOT NULL IDENTITY, [HPlayer1Id] [bigint], [Player1Home_Id] [bigint], CONSTRAINT [PK_Matches] PRIMARY KEY ([Id]) ) CREATE INDEX [IX_Player1Home_Id] ON [Matches]([Player1Home_Id]) CREATE TABLE [Players] ( [Id] [bigint] NOT NULL IDENTITY, CONSTRAINT [PK_Players] PRIMARY KEY ([Id]) ) ALTER TABLE [Matches] ADD CONSTRAINT [FK_Matches_Players_Player1Home_Id] FOREIGN KEY ([Player1Home_Id]) REFERENCES [Players] ([Id]) ```

Commented Issue: Code First: [InverseProperty] and [ForeignKey] DataAnnotations not working properly. [138]

$
0
0
"Repro Steps:
See: http://stackoverflow.com/questions/10020660/why-does-ef-code-first-inverseproperty-attribute-fail-to-work-when-used-with

Actual Results:
Issue 1:EF 4.3.1 - NullReferenceException (EF 4.1 did not have this problem)
Issue 2: An extra Database Column is created for the foreign key that I am already specifying with the DataAnnotation

Expected Results:
Issue 1: No exceptions
Issue 2: A foreign key column should not be auto generated as I am explicitly stating it with a DataAnnotation."

This item was migrated from the DevDiv work item tracking system [ID=397777].

This work item originated from connect.microsoft.com. A member of the EF team at Microsoft should close the related Connect issue when closing this work item.

Comments: Confirmed that in EF6 (and in EF5) we correctly use the existing FK as configured by the annotations: ``` CREATE TABLE [dbo].[Matches] ( [Id] [bigint] NOT NULL IDENTITY, [HPlayer1Id] [bigint], CONSTRAINT [PK_dbo.Matches] PRIMARY KEY ([Id]) ) CREATE INDEX [IX_HPlayer1Id] ON [dbo].[Matches]([HPlayer1Id]) CREATE TABLE [dbo].[Players] ( [Id] [bigint] NOT NULL IDENTITY, CONSTRAINT [PK_dbo.Players] PRIMARY KEY ([Id]) ) ALTER TABLE [dbo].[Matches] ADD CONSTRAINT [FK_dbo.Matches_dbo.Players_HPlayer1Id] FOREIGN KEY ([HPlayer1Id]) REFERENCES [dbo].[Players] ([Id]) ```

Closed Issue: Code First: [InverseProperty] and [ForeignKey] DataAnnotations not working properly. [138]

$
0
0
"Repro Steps:
See: http://stackoverflow.com/questions/10020660/why-does-ef-code-first-inverseproperty-attribute-fail-to-work-when-used-with

Actual Results:
Issue 1:EF 4.3.1 - NullReferenceException (EF 4.1 did not have this problem)
Issue 2: An extra Database Column is created for the foreign key that I am already specifying with the DataAnnotation

Expected Results:
Issue 1: No exceptions
Issue 2: A foreign key column should not be auto generated as I am explicitly stating it with a DataAnnotation."

This item was migrated from the DevDiv work item tracking system [ID=397777].

This work item originated from connect.microsoft.com. A member of the EF team at Microsoft should close the related Connect issue when closing this work item.

Edited Issue: Code First: [InverseProperty] and [ForeignKey] DataAnnotations not working properly. [138]

$
0
0
"Repro Steps:
See: http://stackoverflow.com/questions/10020660/why-does-ef-code-first-inverseproperty-attribute-fail-to-work-when-used-with

Actual Results:
Issue 1:EF 4.3.1 - NullReferenceException (EF 4.1 did not have this problem)
Issue 2: An extra Database Column is created for the foreign key that I am already specifying with the DataAnnotation

Expected Results:
Issue 1: No exceptions
Issue 2: A foreign key column should not be auto generated as I am explicitly stating it with a DataAnnotation."

This item was migrated from the DevDiv work item tracking system [ID=397777].

This work item originated from connect.microsoft.com. A member of the EF team at Microsoft should close the related Connect issue when closing this work item.


Commented Issue: One to Zero-or-One association results in one to many (model designer bug?) [1468]

$
0
0
You can view this issue here: http://stackoverflow.com/questions/17954605/i-found-duplicate-rows-in-sql-for-a-one-to-zero-or-one-entity-framework-relati/17959345?iemail=1&noredirect=1#17959345

At the most basic level, to recreate this issue:

1. Create a new solution. Add an EF data model.
2. From the Model Designer, add two new entities:
Person
Cat
3. Add an association between Person and Cat- one to Zero-or-One
4. Save and generate the database

If we open the EDMX file in an XML editor:

<Association Name="PersonCat">
<End Role="Person" Type="TestModel.Store.People" Multiplicity="1" />
<End Role="Cat" Type="TestModel.Store.Cats" Multiplicity="*" />

Notice the multiplicity for "Cat" is *! This is wrong. This is saying that Person can have multiple Cats. But we all know how crazy this world would be if everyone had multiple cats. That's why we must have a one to zero-or-one relationship between Person and Cat.

It seems at the conceptual level, everything is correct - but at the database level, it's wrong. This results in multiple cats with the same Person_Id, which violates the conceptual model.

Furthermore, this duplicate data will result in exceptions in the conceptual model when you query the database.

Is this a bug in the Entity Framework, or model designer / generator, or is this intended behavior for some obscure reason?

Thanks!
Matt
Comments: As previously noted this is a side effect of EF not supporting unique constraints on non-key properties (which is tracked on our backlog as [Item #299](https://entityframework.codeplex.com/workitem/299)). Because we have no way of modeling that Person_Id has a unique index we can conceptually enforce the 1:0..1 relationship in at the object layer, but in the database we can only model it as a 1:*. This means the 1:0..1 is enforced when using EF, but you could always manually add data to the database that violates it. There is no significant reason for this other than just a limitation of how EF is implemented. When we support unique constraints we will enable this scenario.

Closed Issue: One to Zero-or-One association results in one to many (model designer bug?) [1468]

$
0
0
You can view this issue here: http://stackoverflow.com/questions/17954605/i-found-duplicate-rows-in-sql-for-a-one-to-zero-or-one-entity-framework-relati/17959345?iemail=1&noredirect=1#17959345

At the most basic level, to recreate this issue:

1. Create a new solution. Add an EF data model.
2. From the Model Designer, add two new entities:
Person
Cat
3. Add an association between Person and Cat- one to Zero-or-One
4. Save and generate the database

If we open the EDMX file in an XML editor:

<Association Name="PersonCat">
<End Role="Person" Type="TestModel.Store.People" Multiplicity="1" />
<End Role="Cat" Type="TestModel.Store.Cats" Multiplicity="*" />

Notice the multiplicity for "Cat" is *! This is wrong. This is saying that Person can have multiple Cats. But we all know how crazy this world would be if everyone had multiple cats. That's why we must have a one to zero-or-one relationship between Person and Cat.

It seems at the conceptual level, everything is correct - but at the database level, it's wrong. This results in multiple cats with the same Person_Id, which violates the conceptual model.

Furthermore, this duplicate data will result in exceptions in the conceptual model when you query the database.

Is this a bug in the Entity Framework, or model designer / generator, or is this intended behavior for some obscure reason?

Thanks!
Matt
Comments: This could be considered either 'By Design' or a 'Duplicate' of the Unique Constraint feature (https://entityframework.codeplex.com/workitem/299).

Edited Task: [Performance] Change or remove BooleanSwitch flag [1549]

$
0
0
We have a little known flag that allows query optimization to be turned off for extremely large trees. Best description is here: http://social.msdn.microsoft.com/Forums/en-us/9ab0c472-8571-42d2-a3c4-d4419b529388/include-performance-question

We have to change or remove this for Windows Store apps since BooleanSwitch is not supported. We may choose to remove it given the comment that, “for such queries it takes a long time to simplify only to produce a SQL that is too large for the store to execute.” This suggests that the flag is only about failing faster rather than making anything work.

However, in some cases it _might_ possibly be that it could actually make a query execute faster if we didn’t do optimization, and hence maybe we should make this a configurable setting going forward—that is allow apps to change the number of query nodes above which query optimization would be turned off. Currently the value is 100,000 nodes.

Initial indications are that it will never be worthwhile to switch off optimization as this flag allows, but some additional testing is being done.

Commented Task: [Performance] Change or remove BooleanSwitch flag [1549]

$
0
0
We have a little known flag that allows query optimization to be turned off for extremely large trees. Best description is here: http://social.msdn.microsoft.com/Forums/en-us/9ab0c472-8571-42d2-a3c4-d4419b529388/include-performance-question

We have to change or remove this for Windows Store apps since BooleanSwitch is not supported. We may choose to remove it given the comment that, “for such queries it takes a long time to simplify only to produce a SQL that is too large for the store to execute.” This suggests that the flag is only about failing faster rather than making anything work.

However, in some cases it _might_ possibly be that it could actually make a query execute faster if we didn’t do optimization, and hence maybe we should make this a configurable setting going forward—that is allow apps to change the number of query nodes above which query optimization would be turned off. Currently the value is 100,000 nodes.

Initial indications are that it will never be worthwhile to switch off optimization as this flag allows, but some additional testing is being done.
Comments: Moving out of investigate and setting up title to reflect that this is a work item for David.

Edited Issue: [Performance] Regression introduced to EdmModelDiffer [1662]

$
0
0
Introduced by 43acda2610e9fa4b2899aba293af1635a0320ae6 on August 30th 2013.
https://entityframework.codeplex.com/SourceControl/changeset/43acda2610e9fa4b2899aba293af1635a0320ae6
Impact: major.
Cause: Performance was affected by the changes to the following methods in class EdmModelDiffer: FindRenamedTables(), FindMovedTables(), FindAddedTables(), FindAddedForeignKeys(), FindRemovedTables(), FindRemovedForeignKeys(). The new Linq queries are not performing as well as the old ones used to.

A test is attached to the bug and contains a large model that reproduces the issue.

Closed Issue: Inconsistent handling of Initial Create (automatic vs. explicit) [571]

$
0
0
Update-Database should only give error messages warning of data loss when automatic migrations are not enabled, but if an initial-create migration is created, you are warned of possible data loss if you try to migrate across

Repro:
write application
populate database
PM> Enable-Migrations
add field to Post
PM> Add-Migration m
PM> Update-Database -Script
PM> Update-Database
run app
PM> Update-Database -Script
PM> Update-Database
Update-Database command fails with error: "Column names in each table must be unique. Column name 'S' in table 'dbo.Posts' is specified more than once."
PM> Update-Database -TargetMigration 0
error: Automatic migration was not applied because it would result in data loss.
--when did InitialCreate become an automatic migration?

attached is the package manager log from the session
Comments: The original issue looks like it was caused by a bad ordering of migration commands. The steps we included to block initializers when migrations are enabled seems to have blocked this situation from occurring. This no longer repros

Edited Issue: [Performance] DbContext initialization performance in debug with nigthlybuild package [1272]

$
0
0
We are trying to migrate an existing project from EF 5.0 to EF 6.0.0-beta1-20611.

We found a performance regression in the DbContext initialization process when debugger is attached.
With the same code, the initialization takes approximately 5 seconds with EF 5.0 and 25 seconds with EF 6.0.0-beta1-20611.

We upload a sample solution to illustrate this issue (don't forget to change the connection strings) : [https://docs.google.com/file/d/0B68gjzIGsSurSFFLQUhrNFoxSDA/edit?usp=sharing][1]

Anything wrong in our code or is this a performance regression due to the nightly build environnement ?

[1]: https://docs.google.com/file/d/0B68gjzIGsSurSFFLQUhrNFoxSDA/edit?usp=sharing

New Post: How can I join tables with different data types using Entity Framework

$
0
0
With the situation of using Entity Framework,I want to join tables with two field in same value,but the fields are identified with different data types. For example,there is a field which the data type is 'Guid',but in another table the associated field is 'string' type. I am confused to achieve the goal. Can somebody give me some ideas.Here are my codes:

var dbEmp = zbdlcontext.Emp_Manager;
            var dbCompany = zbdlcontext.Corp_CompanyInfos;
            var dbFlowCode = zbdlcontext.FlowCodes;
            var dbEmpPost = zbdlcontext.Emp_Post;
            var query = from emps in dbEmp
                        join companies in dbCompany on emps.CorpGuid equals companies.CorpUserGuid
                        join flowCode in dbFlowCode on new { EmpGuid = emps.EmpGuid.ToString(), AreaCode = areaCode } equals new { EmpGuid = flowCode.ObjectId, AreaCode = flowCode.AreaCode } into jFlowCodes
                        from flowCodes in jFlowCodes.DefaultIfEmpty()
                        join post in dbEmpPost on emps.EmpGuid equals post.EmpGuid into jPosts
                        from posts in jPosts.DefaultIfEmpty()
                        select new tb_Emp_Manager()
                        {
                            EmpGuid = emps.EmpGuid,
                            AreaCode = emps.AreaCode,
                            FlowCode = flowCodes.FlowCode,
                            corpName = companies.CorpName
                        };
join flowCode in dbFlowCode on new { EmpGuid = emps.EmpGuid.ToString(), AreaCode = areaCode } equals new { EmpGuid = flowCode.ObjectId, AreaCode = flowCode.AreaCode } into jFlowCodes
                        from flowCodes in jFlowCodes.DefaultIfEmpty()

Edited Issue: [NonVS] Power tools: "Sequence contains no element" when Generate Views selected [1287]

$
0
0
I followed the advice on stackoverflow:

* Removed inheritance
* Provided a default constructor
* Moved projects out of solution folders(?!)

But still "Sequence contains no elements". I remember getting this same error when I tried this a year ago.

Edited Issue: Query: Multiple deep includes not processed correctly [1276]

$
0
0
This issue was originally reported via Connect - http://connect.microsoft.com/VisualStudio/feedback/details/789804/ef-not-loading-collection-when-using-include

The query in question has a number of includes that specify multi-level paths, the relationships in question are also quite cyclical.

Here is a simplified repro - the second assert fails.

```
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
Database.SetInitializer(new TestContextInitializer());

using (TestContext context = new TestContext())
{
context.Configuration.LazyLoadingEnabled = false;

Master master = context.Masters
.Where(m => m.Name == "Master1")
.Include("Query.ChildrenA")
.Include("Query.ChildrenB.SpecialQuery.ChildrenA")
.Include("Query.ChildrenB.SpecialQuery.ChildrenB")
.First();
ChildB c = master.Query.GetChildByName("ChildB3");

// Second Assert Fails
Debug.Assert(c.SpecialQuery.ChildrenA.Count == 1);
Debug.Assert(c.SpecialQuery.ChildrenB.Count == 4);
}
}
}

public class Master
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Query Query { get; set; }
}

public class Query
{
public Query()
{
ChildrenA = new HashSet<ChildA>();
ChildrenB = new HashSet<ChildB>();
}
public int Id { get; set; }
public string Name { get; set; }
public Master Master { get; set; }
public ChildB SpecialChild { get; set; }
public virtual ICollection<ChildA> ChildrenA { get; private set; }
public virtual ICollection<ChildB> ChildrenB { get; private set; }

public ChildB GetChildByName(string name)
{
return ChildrenB.Where(c => c.Name == name).FirstOrDefault();
}
}

public class ChildA
{
public int Id { get; set; }
public string Name { get; set; }
public int Query_Id { get; set; }
public virtual Query Query { get; set; }
}

public class ChildB
{
public int Id { get; set; }
public string Name { get; set; }
public virtual Query SpecialQuery { get; set; }
public int Query_Id { get; set; }
public Query Query { get; set; }
}

public class TestContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Master>()
.Property(m => m.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Master>()
.HasKey(m => m.Id);

modelBuilder.Entity<Query>()
.Property(q => q.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<Query>()
.HasKey(q => q.Id);
modelBuilder.Entity<Query>()
.HasOptional(q => q.Master)
.WithOptionalPrincipal(m => m.Query);
modelBuilder.Entity<Query>()
.HasOptional(q => q.SpecialChild)
.WithOptionalPrincipal(c => c.SpecialQuery);

modelBuilder.Entity<ChildA>()
.Property(c => c.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<ChildA>()
.HasKey(c => new { c.Query_Id, c.Id });
modelBuilder.Entity<ChildA>()
.HasRequired(c => c.Query)
.WithMany(q => q.ChildrenA)
.HasForeignKey(c => c.Query_Id);

modelBuilder.Entity<ChildB>()
.Property(c => c.Id)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
modelBuilder.Entity<ChildB>()
.HasKey(c => new { c.Query_Id, c.Id });
modelBuilder.Entity<ChildB>()
.HasRequired(c => c.Query)
.WithMany(m => m.ChildrenB)
.HasForeignKey(c => c.Query_Id);
}

public DbSet<Master> Masters { get; set; }
public DbSet<ChildA> ChildrenA { get; set; }
public DbSet<ChildB> ChildrenB { get; set; }
}

public class TestContextInitializer : DropCreateDatabaseAlways<TestContext>
{
protected override void Seed(TestContext context)
{
Master master = new Master() { Name = "Master1", Query = new Query() { Name = "Query1" } };
master.Query.ChildrenA.Add(new ChildA() { Name = "ChildA1" });
master.Query.ChildrenB.Add(new ChildB() { Name = "ChildB1" });
master.Query.ChildrenB.Add(new ChildB() { Name = "ChildB2" });
master.Query.ChildrenB.Add(new ChildB() { Name = "ChildB3" });
master.Query.ChildrenB.Add(new ChildB() { Name = "ChildB4" });
context.Masters.Add(master);

Query special = new Query() { Name = "Special" };
ChildB c3 = master.Query.GetChildByName("ChildB3");
c3.SpecialQuery = special;
special.ChildrenA.Add(new ChildA() { Name = "SpecialChildA1" });
special.ChildrenB.Add(new ChildB() { Name = "SpecialChildB1" });
special.ChildrenB.Add(new ChildB() { Name = "SpecialChildB2" });
special.ChildrenB.Add(new ChildB() { Name = "SpecialChildB3" });
special.ChildrenB.Add(new ChildB() { Name = "SpecialChildB4" });
context.SaveChanges();
}
}
}
```

Edited Feature: Support creating views from the Designer [1268]

$
0
0
PowerTools added a context menu that allowed generating views for the model. Consider moving this to the designer.
Note: EF6 does not have EdmGen like tool and the only way to generate views for EF6 is to use the T4 template I created (http://visualstudiogallery.msdn.microsoft.com/18a7db90-6705-4d19-9dd1-0a6c23d0751f)
Note: the views for EF5 will have to be generated by EF5 runtime while the views for EF6 will have to be generated with EF6 runtime.

Edited Feature: Provide interception & logging events for transactions [1256]

$
0
0
This would be in general useful to customize the behavior, to include transaction details in the log and also to enable the implementation of workarounds for the issue described here:

[Connection resiliency: possible data corruption if connection fails after transaction commit](https://entityframework.codeplex.com/workitem/1114).


Viewing all 10318 articles
Browse latest View live


Latest Images