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

Created Issue: Designer: Improve perf of Model Browser search in large models [980]

$
0
0
This issue was reported via a private Connect issue.

Searching in Model Browser can hang Visual Studio while searching thru a large model.

Commented Issue: Designer: Improve perf of Model Browser search in large models [980]

$
0
0
This issue was reported via a private Connect issue.

Searching in Model Browser can hang Visual Studio while searching thru a large model.
Comments: **EF Team Triage:** We are only taking minimal changes to the designer in EF6 because we are still converting the code base to open source. We'll consider this issue for the next release.

Created Issue: Code First: TPC with two abstract base classes fails [981]

$
0
0
The following code fails to build a model because there are two abstract base classes before the first concrete class. Removing BillingDetailBase causes the model to be successfully built.

```
public class MyContext : DbContext
{
public DbSet<User> Users { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<BankAccount>().Map(m => { m.ToTable("BankAccounts"); m.MapInheritedProperties(); });
modelBuilder.Entity<CreditCard>().Map(m => { m.ToTable("CreditCards"); m.MapInheritedProperties(); });
}
}

public abstract class BillingDetailBase
{
public Int32 Id { get; set; }
}

public abstract class BillingDetail : BillingDetailBase
{
public string Owner { get; set; }
}

public class User
{
public int UserId { get; set; }
public virtual BillingDetailBase BillingDetail { get; set; }
}

public class BankAccount : BillingDetail
{
public string BankName { get; set; }
public string Swift { get; set; }
}

public class CreditCard : BillingDetail
{
public int CardType { get; set; }
public string ExpiryMonth { get; set; }
public string ExpiryYear { get; set; }
}
```

The error that gets generated is:

```
System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

\tBillingDetailBase: : The referenced EntitySet 'BillingDetailBase' for End 'BillingDetailBase' could not be found in the containing EntityContainer.

at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.DbContextPackage.Handlers.ViewContextHandler.ViewContext(MenuCommand menuCommand, Object context, Type systemContextType)
```

Edited Issue: Code First: TPC with two abstract base classes fails [981]

$
0
0
The following code fails to build a model because there are two abstract base classes before the first concrete class. Removing BillingDetailBase causes the model to be successfully built.

```
public class MyContext : DbContext
{
public DbSet<User> Users { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<BankAccount>().Map(m =>
{
m.ToTable("BankAccounts");
m.MapInheritedProperties();
});

modelBuilder.Entity<CreditCard>().Map(m =>
{
m.ToTable("CreditCards");
m.MapInheritedProperties();
});
}
}

public abstract class BillingDetailBase
{
public Int32 Id { get; set; }
}

public abstract class BillingDetail : BillingDetailBase
{
public string Owner { get; set; }
}

public class User
{
public int UserId { get; set; }
public virtual BillingDetailBase BillingDetail { get; set; }
}

public class BankAccount : BillingDetail
{
public string BankName { get; set; }
public string Swift { get; set; }
}

public class CreditCard : BillingDetail
{
public int CardType { get; set; }
public string ExpiryMonth { get; set; }
public string ExpiryYear { get; set; }
}
```

The error that gets generated is:

```
System.Data.Entity.ModelConfiguration.ModelValidationException: One or more validation errors were detected during model generation:

\tBillingDetailBase: : The referenced EntitySet 'BillingDetailBase' for End 'BillingDetailBase' could not be found in the containing EntityContainer.

at System.Data.Entity.Core.Metadata.Edm.EdmModel.Validate()
at System.Data.Entity.DbModelBuilder.Build(DbProviderManifest providerManifest, DbProviderInfo providerInfo)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.LazyInternalContext.get_CodeFirstModel()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext context, XmlWriter writer)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.DbContextPackage.Handlers.ViewContextHandler.ViewContext(MenuCommand menuCommand, Object context, Type systemContextType)
```

Created Issue: Designer: Unhelpful error message after upgrading to VS2012 using a third party provider [982]

$
0
0
This issue was reported via Connect http://connect.microsoft.com/VisualStudio/feedback/details/761883/vs-give-unknown-error-message-while-generating-db-from-ef

The Connect issue records that a few different folks have hit this problem. We haven't been able to reproduce it but it seems like the steps are:
1. Create a model that targets a non-SQL Server database using VS2010
1. Upgrade to VS2012
1. Select 'Generate database from model...'

The result is an error:
```
---------------------------
Microsoft Visual Studio
---------------------------
An exception of type 'Microsoft.VSDesigner.Data.Local.ConnectionStringConverterServiceException' occurred while attempting to generate the database script from the model. The exception message is: ''.
---------------------------
ОК
---------------------------
```

We definitely need to fix the error message (note the empty string at the end of the message). It looks like ConnectionStringConverterServiceException is owned by another team at Microsoft so we will probably need their help.

If we are able to reproduce the issue we also need to understand why the connection string is becoming invalid.


Here are some notes on a workaround provided by Lawrence:
> The error is coming from not being able to interpret the connection string. We don't own the module that does that but from reading the forums it looks like this can often happen if the provider is not properly installed. So if you are upgrading VS make sure you re-install your provider. Once that's done, as an easy workaround, comment out the relevant connection string in your app or web.config. Then go through "Update Model from Database" (selecting nothing new if that's what you want). When it detects that there is no connection string associated with the model it will offer you the page where you get to choose which connection to use. Select your connection and a new connection string with the appropriate format should be put in your .config file.

Edited Issue: Designer: Unhelpful error message after upgrading to VS2012 using a third party provider [982]

$
0
0
This issue was reported via Connect http://connect.microsoft.com/VisualStudio/feedback/details/761883/vs-give-unknown-error-message-while-generating-db-from-ef

The Connect issue records that a few different folks have hit this problem. We haven't been able to reproduce it but it seems like the steps are:
1. Create a model that targets a non-SQL Server database using VS2010
1. Upgrade to VS2012
1. Select 'Generate database from model...'

The result is an error:
```
---------------------------
Microsoft Visual Studio
---------------------------
An exception of type 'Microsoft.VSDesigner.Data.Local.ConnectionStringConverterServiceException' occurred while attempting to generate the database script from the model. The exception message is: ''.
---------------------------
ОК
---------------------------
```

We definitely need to fix the error message (note the empty string at the end of the message). It looks like ConnectionStringConverterServiceException is owned by another team at Microsoft so we will probably need their help.

If we are able to reproduce the issue we also need to understand why the connection string is becoming invalid.


Here are some notes on a workaround provided by Lawrence:
> The error is coming from not being able to interpret the connection string. We don't own the module that does that but from reading the forums it looks like this can often happen if the provider is not properly installed. So if you are upgrading VS make sure you re-install your provider. Once that's done, as an easy workaround, comment out the relevant connection string in your app or web.config. Then go through "Update Model from Database" (selecting nothing new if that's what you want). When it detects that there is no connection string associated with the model it will offer you the page where you get to choose which connection to use. Select your connection and a new connection string with the appropriate format should be put in your .config file.

Commented Feature: Use NEWSEQUENTIALID() instead of NEWID() for GUID keys [71]

$
0
0
This item was migrated from the DevDiv work item tracking system [ID=32229].

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: Also see: http://entityframework.codeplex.com/wikipage?title=Design%20Meeting%20Notes%20-%20January%2010%2c%202013

Created Feature: LINQ to Entities: Support String.IsNullOrWhitespace() [983]

$
0
0
The CLR method `String.IsNullOrWhitespace()` should be mapped to the canonical function `IsNull(value) OR Length(Trim(value)) = 0`


Edited Feature: LINQ to Entities: Support String.IsNullOrWhitespace() [983]

$
0
0
The CLR method `String.IsNullOrWhitespace()` should be mapped to the canonical function `IsNull(value) OR Length(LTrim(value)) = 0`

Commented Feature: LINQ to Entities: Support String.IsNullOrWhitespace() [983]

$
0
0
The CLR method `String.IsNullOrWhitespace()` should be mapped to the canonical function `IsNull(value) OR Length(LTrim(value)) = 0`

Comments: Actually, this may not be the right thing to do. SQL Server's LTRIM function may use a different set of "whitespace" characters...

Commented Issue: VarBinary IsMaxLength causes FormatException in EF CodeFirst [552]

$
0
0
In the previous version this functionality was working fine. Probably with the introduction with EF migrations this bug was introduced (looking at the stacktrace). We have a property of type byte[] which we store as a varbinary, in the configuration class of the entity we use the following line:

this.Property(m => m.CustomProperty).IsRequired().HasColumnType("VarBinary").IsMaxLength(); //ERROR

this.Property(m => m.CustomProperty).IsRequired().HasColumnType("VarBinary").HasMaxLength(8000)(); //NO ERROR


at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Convert.ToInt32(String value)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildColumnModel(XElement property, String entitySetName, ModelMetadata modelMetadata)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<>c__DisplayClass125.<BuildCreateTableOperation>b__123(XElement p)
at System.Data.Entity.Migrations.Extensions.IEnumerableExtensions.Each[T](IEnumerable`1 ts, Action`1 action)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.BuildCreateTableOperation(String entitySetName, String tableName, String schema, ModelMetadata modelMetadata)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.<FindAddedTables>b__31(XElement es)
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at System.Data.Entity.Migrations.Infrastructure.EdmModelDiffer.Diff(XDocument sourceModel, XDocument targetModel, String connectionString)
at System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.AutoMigrate(String migrationId, XDocument sourceModel, XDocument targetModel, Boolean downgrading)
at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Upgrade(IEnumerable`1 pendingMigrations, String targetMigrationId, String lastMigrationId)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
at System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext)
at System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext)
at System.Data.Entity.Database.CreateIfNotExists()
at ANAAC.TCC.Fractal.Data.Dialogs.OpenConnectionDialog.CreateDatabase(String path) in

The error pops up for both SQL compact and SQL Server databases.

Because we dont have VS2012 we could not run the ef project, but looking at the code we think that the problem lies in the following class:
-class:EdmModelDiffer -> method:BuildColumnModel ->
= new ColumnModel(((PrimitiveType)edmProperty.TypeUsage.EdmType).PrimitiveTypeKind, typeUsage)
{
Name = nameAttribute,
IsNullable
= !string.IsNullOrWhiteSpace(nullableAttribute)
&& !Convert.ToBoolean(nullableAttribute, CultureInfo.InvariantCulture)
? false
: (bool?)null,
MaxLength
= !string.IsNullOrWhiteSpace(maxLengthAttribute)
? Convert.ToInt32(maxLengthAttribute, CultureInfo.InvariantCulture)
: (int?)null,

Environment:
- Windows XP
- VS2010
- .Net 4.0
- SQL Compact 4.0 SP1

Kind regards,

W. Kosten
Comments: This applies not only to VarBinary but also to VarChar and NVarChar fields.

Edited Feature: Use NEWSEQUENTIALID() instead of NEWID() for GUID keys [71]

$
0
0
This item was migrated from the DevDiv work item tracking system [ID=32229].

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.

Source code checked in, #81550b43907b

$
0
0
Fix debug build test failures due to erroneous asserts/assumptions.

Commented Issue: Code First: Allow subclasses to map field to same database column with TPH inheritance [583]

$
0
0
When using TPH inheritance, Code First requires every field defined in a subclass to be mapped to a unique database column. However, there are scenarios where it would be simpler for subclasses to map fields to the same column. For example:

public abstract class Vehicle { ... }

public class Car : Vehicle { ... }

public class Truck : Vehicle { ... }

public class Trike : Vehicle { public string WheelOrientation { get; set; } ... }

public class CanAmSpyder : Vehicle { public string WheelOrientation { get; set; } ... }

Given the above example with Code First TPH, the database table "Vehicle" would require two columns for wheel orientation: "TrikeWheelOrientation" and "CanAmSpyderWheelOrientation". But having a single "WheelOrientation" column that both the Trike subclass and CanAmSpyder subclass can map to seems cleaner.
Comments: +100 this is a big problem when using TPH. I hope it gets fixed yesterday.

Created Issue: Supporting Azure Federated SQL Database: Cannot Not Have Transaction Automatically Wrapped Around Database.ExecuteSqlCommand(commandText) [984]

$
0
0
Hi there

As a heads up...

For a while now we've successfully been using EF 5.0 with an Azure Federated SQL Database on a greenfield project (not production ready).

In order to do so, the first command that needs to be run is the "USE FEDERATION" statement and then subsequent commands on the same open connection.

This is relatively trivial to do:

```
private static void ExecuteCommand(this System.Data.Entity.DbContext ctx, string commandText)
{
var conn = ((IObjectContextAdapter) ctx).ObjectContext.Connection;
conn.Open();
ctx.Database.ExecuteSqlCommand(commandText);
}

```

In the above example, the 'commandText' being passed in is "USE FEDERATION ROOT WITH RESET" via an extension method and then a lamda expression is used on the DbContext object to get the desired result. This has been working well.

I decided to dump in EF 6.0 Alpha 3 and have a play with the new built-in support for transient faults. Oh dear...

With no code change we are suddenly getting an error from SQL Database:
.

> System.Data.SqlClient.SqlException: "USE FEDERATION ROOT statement not allowed within multi-statement transaction."

.

It appears as though EF 6 is automatically wrapping a transaction around the "ExecuteSqlCommand()".

We've tried a couple of different ways to turn off transactions. Neither works:

```
private static void ExecuteCommand(this System.Data.Entity.DbContext ctx, string commandText)
{
var conn = ((IObjectContextAdapter) ctx).ObjectContext.Connection;
conn.Open();
ctx.Database.UseTransaction(null);
ctx.Database.ExecuteSqlCommand(commandText);
}

```

```
private void SetFederationScope()
{
using (new TransactionScope(TransactionScopeOption.Suppress))
{
Context.UseFederationRoot();
}
}

```

Whilst I have your attention, of course it would be great to get first class support for federated databases such as something like but I'm not holding my breath:

```
[FederatedEntity(FederationKey = "Id")]
public class UserProfile
{
public int Id { get; set; }
public string DisplayName { get; set; }
public string EmailAddress { get; set; }
public DateTime? DOB { get; set; }
}

[NonFederatedEntity]
public class Region
{
public int Id { get; set; }
public string Name { get; set; }
}

```

In the least we need a way to turn off transactions in this scenario. Also, I remember reading something a few weeks back about EF 6 DbContext now supporting the use of an already open connection? Wondering if it's possible to open the connection and run the federation statement and then pass the connection to DbConntext...? Hmmmm..... I might play a little more... That could have merit. :)

Source code checked in, #c43e3bf466a0

$
0
0
TimeGotTheTimeTickTickTickinInMyHead (Add first-class support for CommandTimeout in DbContext) It was previously possible to set the CommandTimeout for most operations by dropping down to ObjectContext. This change introduces a property of context.Database.CommandTimeout which will be used for all operations of the context. This includes DDL and implicit Migrations operations. Static (i.e. non-context) DDL methods on database obviously don't use this timeout. DbMigrationsConfiguration already contained a CommandTimeout property used when running Migrations. This is now also used for history context operations.

Edited Issue: EF 6 and SQL Azure Federations [978]

$
0
0
Hi,

I'm currently working on a new project with EF6 (ntityFramework 6.0.0-alpha3) and I encounter a problem with the SQL Azure federations...

According to [this article (2013-01-07)](http://msdn.microsoft.com/en-us/library/windowsazure/hh703245.aspx), I send the USE statement and I open a new transaction:

```
using (TestEntities dc = new TestEntities())
{
((IObjectContextAdapter)dc).ObjectContext.Connection.Open();
dc.Database.ExecuteSqlCommand(@"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"); // Exception occurs here

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
[.......]
scope.Complete();
}
}
```

With Entity Framework 5 installed, the "USE FEDERATION..." is accepted but with Entity Framework 6 (same code, juste a different version of EF), an exception occurs: "USE FEDERATION statement not allowed within multi-statement transaction."

Anyone has a idea why it does not work?

Thanks in advance!

Commented Issue: EF 6 and SQL Azure Federations [978]

$
0
0
Hi,

I'm currently working on a new project with EF6 (ntityFramework 6.0.0-alpha3) and I encounter a problem with the SQL Azure federations...

According to [this article (2013-01-07)](http://msdn.microsoft.com/en-us/library/windowsazure/hh703245.aspx), I send the USE statement and I open a new transaction:

```
using (TestEntities dc = new TestEntities())
{
((IObjectContextAdapter)dc).ObjectContext.Connection.Open();
dc.Database.ExecuteSqlCommand(@"USE FEDERATION TestFederation (FederationKey=0) WITH FILTERING = OFF, RESET"); // Exception occurs here

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
{
[.......]
scope.Complete();
}
}
```

With Entity Framework 5 installed, the "USE FEDERATION..." is accepted but with Entity Framework 6 (same code, juste a different version of EF), an exception occurs: "USE FEDERATION statement not allowed within multi-statement transaction."

Anyone has a idea why it does not work?

Thanks in advance!
Comments: **EF Team Triage:** Assigning to a member of the EF team for further investigation.

Created Issue: Consider adding CommandTimeout to static Database methods [985]

$
0
0
The non-static methods on Database use the CommandTimeout set for the context using the Database.CommandTimeout property. Static methods obviously can't use this, so we should consider adding an overload that takes a timeout. However, consider:
* It's not clear how useful a timeout really is for these types of operation (Delete/Exists)
* It's not clear how often the static methods are used
* It is easy to new up a context and use the non-static methods if a timeout really is needed

Edited Feature: Code First: Allow timeout to be set for DbSet.SqlQuery [59]

$
0
0
This item was migrated from the DevDiv work item tracking system [ID=307945].

Viewing all 10318 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>