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

New Post: Support SQL Server HierarchyId data type

$
0
0
Thanks for the fast reply!

I did have regular EntityFramework installed first.

After I uninstalled both, then installed EntityFrameworkWithHierarchyId it now appears to work.

Is there any support for "from database"? (I guess I will find out soon when I try it)

New Post: Support SQL Server HierarchyId data type

$
0
0
If I have EntityFrameworkWithHierarchyId installed (but not EnitityFramework), then when I try to do "Code first from Database" I get the error:
   The EntityFramework package is not installed on project
Does EntityFrameworkWithHierarchyId not support "from Database" at all? I thought as a minor extension, it would otherwise work the same as regular EntityFramework.

Is the only way to use this with "Code first from Database" to first install regular EntityFramework, then add/update with "Code first from Database", then uninstall regular EntityFramework, then install EntityFrameworkWithHierarchyId ?

Is there a better way?

New Post: Support SQL Server HierarchyId data type

New Post: Support SQL Server HierarchyId data type

$
0
0
I'm not sure I have time to do that.

Would this workaround be effective? Or are there hidden problems with this?
  1. (for update only) Uninstall EntityFrameworkWithHierarchyId
  2. Install EntitfyFramework (regular)
  3. Do "Code First from Database" (either new or update)
  4. Uninstall EntityFramework (regular)
  5. Install EntityFrameworkWithHierarchyId
  6. Manually edit classes to include HierarchyId properties (best to use partial class in a separate file, so updates do no erase prior changes)

New Post: Support SQL Server HierarchyId data type

$
0
0
When installing EntityFrameworkWithHierarchyId6.1.3 with NuGet, the output window indicates success, but I get the following error message, repeated many times for different types.

These errors seem to be generated by the EntityFrameworkWithHierarchyId.6.1.3\tools\init.ps1 script:
Executing script file 'D:\repos\................................................\packages\EntityFrameworkWithHierarchyId.6.1.3\tools\init.ps1'...
The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(32) : Error in type "__System.Xml.XmlNode__": Exception: Cannot create a code method because of the method format. The method should be public, static, and have one parameter of type PSObject.
The first few types are System.Xml.XmlNode, System.Xml.XmlNodeList, System.DirectoryServices.PropertyValueCollection, System.DirectoryServices.DirectoryEntry and so on.

Then there are many errors like this:
There were errors in loading the format data file: Microsoft.PowerShell.Core, Error at XPath /Configuration/Controls/Control[1]/CustomControl/CustomEntries/CustomEntry[1]/CustomItem/Frame[1]/CustomItem/Text[1] in file C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Certificate.format.ps1xml: Resource FileSystemProviderStrings in assembly C:\System.Management.Automation is not found.
Despite the above errors, the output concludes with a success message:
Executing script file 'D:\repos\................................\packages\EntityFrameworkWithHierarchyId.6.1.3\tools\install.ps1'...

Type 'get-help EntityFramework' to see all available Entity Framework commands.
Successfully installed 'EntityFrameworkWithHierarchyId 6.1.3' to Trac.EntityModel_CffD
Should I trust that it was installed successfully?

New Post: Support SQL Server HierarchyId data type

$
0
0
Sorry, I don't know. I created this package, because needed the hierarchyid support 3 years ago. But I haven't used this package since a year ago. I updated it to 6.1.3 only because somebody asked me.

New Post: Support SQL Server HierarchyId data type

New Post: Support SQL Server HierarchyId data type

$
0
0
It is because it is a fork, most of the code comes from MS:)
I don't know what is the legal way in this case, if somebody from MS writes me to remove it, I'll remove Microsoft from the author list.

Created Unassigned: Null Reference Exception generating views [2862]

$
0
0
When using Visual Studio 2012 with Update 5 and EF 6.1.3, when I click on
Entity Framework > Generate Views, I get a NullReferenceException in Microsoft.DbcontextPackage.Handlers.OptimizeContextHandler.OptimizeEmdx

The NullReferenceException was the result of the type resolution service not being able to resolve the EF6 assembly (ef6Assembly == null).

Edited Unassigned: Null Reference Exception generating views using Power Tools [2862]

$
0
0
When using Visual Studio 2012 with Update 5 and EF 6.1.3 and the EF 6 Power Tools, when I click on
Entity Framework > Generate Views, I get a NullReferenceException in Microsoft.DbcontextPackage.Handlers.OptimizeContextHandler.OptimizeEmdx

The NullReferenceException was the result of the type resolution service not being able to resolve the EF6 assembly (ef6Assembly == null).

Commented Unassigned: Null Reference Exception generating views using Power Tools [2862]

$
0
0
When using Visual Studio 2012 with Update 5 and EF 6.1.3 and the EF 6 Power Tools, when I click on
Entity Framework > Generate Views, I get a NullReferenceException in Microsoft.DbcontextPackage.Handlers.OptimizeContextHandler.OptimizeEmdx

The NullReferenceException was the result of the type resolution service not being able to resolve the EF6 assembly (ef6Assembly == null).
Comments: The proposed fix is to OptimizeContextHandler.cs in the PowerTools project is (from line 106): var typeService = _package.GetService<DynamicTypeService>(); var solution = _package.GetService<SVsSolution, IVsSolution>(); IVsHierarchy hierarchy; solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy); var typeResolutionService = typeService.GetTypeResolutionService(hierarchy); var ef6Assembly = typeResolutionService.GetAssembly( new AssemblyName { Name = ef6Reference.Name, Version = new Version(ef6Reference.Version) }); ``` if (ef6Assembly != null) { string containerName; var mappingCollection = edmxUtility.GetMappingCollectionEF6(ef6Assembly, out containerName); var contextTypeName = selectedItem.ProjectItem.GetDefaultNamespace() + "." + containerName; OptimizeContextEF6(languageOption, baseFileName, mappingCollection, selectedItem, contextTypeName); } else { var mappingCollection = edmxUtility.GetMappingCollection(); OptimizeContextEF5(languageOption, baseFileName, mappingCollection, selectedItem); } ```

New Post: EDMX designer can't see my EF6 provider

$
0
0
Yes, installed - VS is at update 5, just in case. No way. Any hint?

Source code checked in, #24b2f52a1dd87462a506689f5f4284607ab32111

$
0
0
Merging with release-6.1.3-tools-update-1 branch.

Created Unassigned: Adding entries of an entity to the database sometimes does not affect the indexes. Lots of indexes remain unaffected. [2863]

$
0
0
Indexes are not being set when inserting rows in the following, fully-working example. The index is being created but when it's being added as a relationship, it's not using the index. No index leaves get created. This is what I'm seeing. http://imgur.com/a/ctvVP

If I change:

//Join the relations
host.Programs.Add(program);

ctx.Hosts.Add(host);

//Save
ctx.SaveChanges();

To

ctx.Programs.Add(program);

//Save
ctx.SaveChanges();

The index works and I get leaves. Any ideas?

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Data.Entity.ModelConfiguration.Configuration;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.SqlClient;
using System.IO;

namespace dbtest
{
class ProgramTest
{
static void Main(string[] args)
{
//Uses nuget package LocalDbApi
//Start a localdb instance. Delete the old one if necessary
var localDb = new LocalDbApi.Instance();
try { localDb.StopInstance("dust");} catch { }
if (File.Exists("c:\\users\\james\\test.mdf")) File.Delete("c:\\users\\james\\test.mdf");
if (File.Exists("c:\\users\\james\\test_log.ldf")) File.Delete("c:\\users\\james\\test_log.ldf");
try { localDb.GetInstance("dust"); } catch { localDb.Create("dust"); }
localDb.StartInstance("dust");

//Create the Db
Database.SetInitializer(new CreateDatabaseIfNotExists<DustContext>());
using (var ctx = new DustContext())
{
ctx.Database.Log = Console.Write;

ctx.Database.Create();

//Add the data
var host = new Host()
{
Hostname = "192.168.0.1",
Programs = new List<Program>()
};
var program = new Program()
{
DisplayName = "foo",
Architecture = 1,
Disposition = 0,
Publisher = "bar",
Version = "14684"
};

//Join the relations
host.Programs.Add(program);

ctx.Hosts.Add(host);

//Save
ctx.SaveChanges();
}

Console.Write("Press any key to continue ...");
Console.ReadKey();
}

public class DustContext : DbContext
{
public DbContextConfiguration Config => Configuration;

//My models
public DbSet<Program> Programs { get; set; }
public DbSet<Host> Hosts { get; set; }

//Connection String
public DustContext() : base(new SqlConnection() { ConnectionString = @"data source = (LocalDb)\dust;Trusted_Connection=False;Integrated Security=true;AttachDbFilename=c:\users\james\test.mdf" }, true) { }

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new ProgramMap());
}
}
}


/***************************************************************
*
* Entities
*
***************************************************************/

public class Program
{
public int Id { get; set; }

//Composite key on these three
public string DisplayName { get; set; }
public string Publisher { get; set; }
public string Version { get; set; }

public Int32 Architecture { get; set; }
public int Disposition { get; set; }
}

public class ProgramMap : EntityTypeConfiguration<Program>
{
public ProgramMap()
{
Property(a => a.DisplayName)
.HasMaxLength(512)
.HasCompositeIndexAnnotation("IX_ProgramDisplayNamePublisherVersion", 1);
Property(a => a.Publisher)
.HasMaxLength(512)
.HasCompositeIndexAnnotation("IX_ProgramDisplayNamePublisherVersion", 2);
Property(a => a.Version)
.HasMaxLength(512)
.HasCompositeIndexAnnotation("IX_ProgramDisplayNamePublisherVersion", 3);
}
}

public class Host
{
public int Id { get; set; }
public string Hostname { get; set; }
public virtual List<Program> Programs { get; set; }
}

}

/// <summary>
/// Applies an index on composite columns
/// </summary>
internal static class TypeConfigurationExtensions
{
public static PrimitivePropertyConfiguration HasCompositeIndexAnnotation(
this PrimitivePropertyConfiguration property,
string indexName,
int columnOrder)
{
var indexAttribute = new IndexAttribute(indexName, columnOrder) { IsUnique = false };
var indexAnnotation = new IndexAnnotation(indexAttribute);

return property.HasColumnAnnotation(IndexAnnotation.AnnotationName, indexAnnotation);
}
}

Here's the output to the console:

> INSERT [dbo].[Host]([Hostname]) VALUES (@0) SELECT [Id] FROM [dbo].[Host] WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()

> -- @0: '192.168.0.1' (Type = String, Size = -1)

> INSERT [dbo].[Program]([DisplayName], [Publisher], [Version], [Architecture], [D isposition], [Host_Id]) VALUES (@0, @1, @2, @3, @4, @5) SELECT [Id] FROM [dbo].[Program] WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()

> -- @0: 'foo' (Type = String, Size = 512)

> -- @1: 'bar' (Type = String, Size = 512)

> -- @2: '14684' (Type = String, Size = 512)

> -- @3: '1' (Type = Int32)

> -- @4: '0' (Type = Int32)

> -- @5: '1' (Type = Int32)


If I actually run this against an empty database from Visual Studio, it works.

BEGIN TRAN T1

INSERT [dbo].Host VALUES ('192.168.0.1') SELECT [Id] FROM [dbo].[Host] WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()

INSERT [dbo].[Program]([DisplayName], [Publisher], [Version], [Architecture], [Disposition], [Host_Id]) VALUES ('foo', 'bar', '14684', '1', '0', '1') SELECT [Id] FROM [dbo].[Program] WHERE @@ROWCOUNT > 0 AND [Id] = scope_identity()

COMMIT TRAN T1

Created Unassigned: Allow for the ability to use EF POCO Proxies on internal classes [2864]

$
0
0
This was opened on the ASP.NET UserVoice site. Please triage as appropiate.
https://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/488743-allow-for-the-ability-to-use-ef-poco-proxies-on-in

Reviewed: EF 6.1.0 (12月 10, 2015)

$
0
0
Rated 5 Stars (out of 5) - excellent good see it

Created Unassigned: Issue with Transforming T4 template after upgrading from Visual Studio 2012 to 2015 [2865]

$
0
0
I am receiving an error when trying to transform my T4 templates after upgrading from Visual Studio 2012 to Visual Studio 2015. The error only occurs in 2015 and is the following:

Severity Code Description Project File Line
Error Running transformation: System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.InvalidCastException: [A]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection cannot be cast to [B]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection. Type A originates from 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'Default' at location 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\EntityFramework.dll'. Type B originates from 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadFrom' at location 'C:\Users\mball\AppData\Local\assembly\dl3\NEL04YEP.L5W\XZMTJ8Y3.AQX\ae6c1d7c\1c6dded0_2329d101\EntityFramework.dll'.
at System.Data.Entity.Internal.AppConfig..ctor()
at System.Data.Entity.Internal.AppConfig..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at MTO.Data.ContextBase..ctor(String connectionString, IQueueManager queueManager)
at MTO.Data.ContextBase`1..ctor(String connectionString, IQueueManager queueManager)
at MTO.Data.ContextMto..ctor(String connectionString, IQueueManager queueManager)
at Microsoft.VisualStudio.TextTemplatingB4C6A10D5E27D5BF6972752E5B6D34223C87F4730BABFA9C092B8771FD2D15FC2EB19F98F101F45D4F150804395E45CE9894426D3242245FCA85F81B4F3FDE01.GeneratedTextTransformation.TransformText() in d:\tfs\ThirtyOnePPSource\ThirtyOne PPS 2\WB_Release151208-Outlet\Integral.Web.UI\Scripts\Mto\Mto.LocalizedText.tt:line 81 Integral.Web.UI d:\tfs\ThirtyOnePPSource\ThirtyOne PPS 2\WB_Release151208-Outlet\Integral.Web.UI\Scripts\Mto\Mto.LocalizedText.tt 81

The resulting file is blank from the T4 template transformation.

I'm able to reproduce the same in Visual studio 2013 Ultimate as well.

Current workaround is to delete the Entity Framework DLL's from the directory "'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE"


Edited Unassigned: Issue with Transforming T4 template after upgrading from Visual Studio 2012 to 2015 [2865]

$
0
0
I am receiving an error when trying to transform my T4 templates after upgrading from Visual Studio 2012 to Visual Studio 2015. The error only occurs in 2015 and is the following:

Severity Code Description Project File Line
Error Running transformation: System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.InvalidCastException: [A]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection cannot be cast to [B]System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection. Type A originates from 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'Default' at location 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\EntityFramework.dll'. Type B originates from 'EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadFrom' at location 'C:\Users\Test\AppData\Local\assembly\test\XZMTJ8Y3.AQX\ae6c1d7c\1c6dded0_2329d101\EntityFramework.dll'.
at System.Data.Entity.Internal.AppConfig..ctor()
at System.Data.Entity.Internal.AppConfig..cctor()
--- End of inner exception stack trace ---
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)
at Test.Data.ContextBase..ctor(String connectionString, IQueueManager queueManager)
at Test.Data.ContextBase`1..ctor(String connectionString, IQueueManager queueManager)
at Test.Data.ContextMto..ctor(String connectionString, IQueueManager queueManager)
at Microsoft.VisualStudio.TextTemplatingB4C6A10D5E27D5BF6972752E5B6D34223C87F4730BABFA9C092B8771FD2D15FC2EB19F98F101F45D4F150804395E45CE9894426D3242245FCA85F81B4F3FDE01.GeneratedTextTransformation.TransformText() in d:\Test\Test1\Test2\Test3\test.tt:line 81 Integral.Web.UI d:\Test\Test1\Test2\Test3\test.tt 81

The resulting file is blank from the T4 template transformation.

I'm able to reproduce the same in Visual studio 2013 Ultimate as well.

Current workaround is to delete the Entity Framework DLL's from the directory "'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE"

Source code checked in, #89acc0ad9578463a499364d44e1858cc5108b67b

$
0
0
Fix typo in xml doc comments for DbMigrationsConfiguration

Created Unassigned: Use the method ExtendedSqlAzureExecutionStrategy.ExecuteNew consistently [2866]

$
0
0
On previous commit (1571862), I identified that you make the following change on class a/test/EntityFramework/FunctionalTests/Interception/CommitFailureTests.cs:
- c => Assert.Throws<DataException>(() => c()).InnerException.ValidateMessage("CommitFailed"),
+ c => Assert.Throws<DataException>(() => ExtendedSqlAzureExecutionStrategy.ExecuteNew(c)).InnerException.ValidateMessage("CommitFailed"),
and
- c => Assert.Throws<CommitFailedException>(() => c()).ValidateMessage("CommitFailed"),
+ c => Assert.Throws<CommitFailedException>(() => ExtendedSqlAzureExecutionStrategy.ExecuteNew(c)).ValidateMessage("CommitFailed"),

There are other locations following the pattern that was changed. Maybe the other locations must also be changed.
Viewing all 10318 articles
Browse latest View live




Latest Images