Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all 1793 articles
Browse latest View live

New Post: EF6 startup performance

$
0
0
Hi Diego,

I have sent the project to your email address. I have packed it with Ef6 library, so you can immediately reproduce the problem. However, if there is a problem with email size (approx 8MB), I am going to remove the EF6 package from it.

Regards,
Goran

New Post: Testing with async queries doesn't work

$
0
0
I've run into the same issue using the Test Doubles example TestDoubles instead of the mocking example. I'll check when I go to work tomorrow but I have found some queries work such as FirstAsync but ToListAsync and FirstOrDefaultAsync do not.

New Post: EF6, Enumerable.Contains and auto compilation

$
0
0
This is actually not true. A trip through the source code today reveals that any queries containing an IEnumerable<T> parameter are ALWAYS invalidated since an item in the collection "could change". The point here is valid, but the performance is still awful.

New Post: EF6 runtime DbContext/ObjectContext supports MEST?

$
0
0
Hi Diego.

I checked the new version 1763ddb2f4f8.

It works well.
I can get SchemaInformation from both System.Data.SqlClient and Npgsql providers!

Sorry for taking so much time to verify your fix. I had trouble with EF relationship.

I knew:
  • ObjectContext.CreateQuery won't solve relationship.
  • ObjectContext.CreateObjectSet will solve relationship.
I'm using mapping view generated by EdmGen in .NET3.5. It uses CreateQuery for tables.
I noticed EdmGen in .NET4.5 uses CreateObjectSet.

I'll use CreateObjectSet, and it works well :)

thanks
kenji uno

New Post: load master and refresh details,how to?

$
0
0
table a,table b
first a.load();
then find a with include "b"

here i update b with sql in sqlserver managerment
if I use objectContext.Refresh(RefreshMode.StoreWins, b.Local); I can get the new b items with a;

I use the generic repository,in my find fuction my code like :
           var query = ctx.Set<T>().Where(t => true);
            foreach (string include in includes)
            {
                query = query.Include(include);
                query.Load();
            }
            query.Load();
            result.Entities = query.Where(filter.Compile());
always not refresh the b object from database.

New Post: Spatial DataReader and Wrapping Providers in EF6

$
0
0
To get my head around the new style of wrapping providers in EF6 I have put a quick sample together but I am struggling when it comes to the spatial data reader.

The exception I get is
Specified type is not registered on the target server.System.Data.Entity.Spatial.DbGeometry, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089.
I have also asked the question at Stack Overflow
http://stackoverflow.com/questions/19966106/spatial-datareader-and-wrapping-providers-in-ef6

If anyone could help me identify what is wrong it would be much appreciated.
I thought I had followed this article, but I must be missing something?
https://entityframework.codeplex.com/wikipage?title=Rebuilding%20EF%20providers%20for%20EF6

I will reply with the sample code. (as there is a content limit for this discussion)

New Post: Spatial DataReader and Wrapping Providers in EF6

$
0
0
Model
public class TestEF6DataSource : DbContext
{
    public DbSet<MattShape> MattShapes { get; set; }
}

public class MattShape
{
    [Key]
    public int MattShapeId { get; set; }

    [Required]
    public DbGeometry GeoShape { get; set; }
}
Migrations
public sealed class Configuration : DbMigrationsConfiguration<TestEF6DataSource>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(TestEF6DataSource context)
    {
    context.MattShapes.AddOrUpdate(
        m => m.MattShapeId,
        new MattShape { MattShapeId = 1, GeoShape = DbGeometry.FromText("POLYGON ((1843503.54576196 5743170.10983084, 1843627.97736856 5743384.66544795, 1843557.59765677 5743393.36080548, 1843362.48753989 5743417.46230251, 1843361.11361057 5743417.63180584, 1843358.43835504 5743418.34609364, 1843355.88774656 5743419.42171531, 1843353.50983276 5743420.83971631, 1843352.42925232 5743421.70492403, 1843051.20263201 5743663.02873092, 1843050.40246141 5743663.67014246, 1843048.94101245 5743665.10920791, 1843047.63448048 5743666.69052689, 1843046.49589101 5743668.39810608, 1843045.53827419 5743670.21195005, 1843044.77165509 5743672.11506149, 1843044.20306302 5743674.085437, 1843043.83952263 5743676.10507526, 1843043.76129276 5743677.12752066, 1843043.68306289 5743678.14996605, 1843043.73770804 5743680.20110406, 1843044.00148376 5743682.23547495, 1843044.47141291 5743684.23206429, 1843045.14351779 5743686.16985646, 1843046.01081798 5743688.02883293, 1843047.06232975 5743689.78997102, 1843048.28907043 5743691.4342504, 1843048.98356169 5743692.18944876, 1843227.79751488 5743886.66320856, 1843370.49789926 5744041.86289133, 1843211.63121968 5744181.85544627, 1843210.88004919 5744182.51692323, 1843209.51761462 5744183.9841149, 1843208.30811202 5744185.57955102, 1843207.26456693 5744187.28723829, 1843206.3960028 5744189.09117878, 1843205.7124471 5744190.97237412, 1843205.219924 5744192.91282186, 1843204.92345948 5744194.89251733, 1843204.87426871 5744195.89198485, 1843204.82507793 5744196.89145237, 1843204.92780195 5744198.89162105, 1843205.22865675 5744200.87000785, 1843205.72666166 5744202.80960272, 1843206.41483744 5744204.68938653, 1843207.28720192 5744206.49134292, 1843208.33477247 5744208.1964515, 1843209.548563 5744209.78869344, 1843210.23107302 5744210.52086848, 1843362.82471731 5744374.04062576, 1843521.47199211 5744544.04810409, 1843522.80403726 5744545.4754015, 1843525.96805836 5744547.76127718, 1843529.51504843 5744549.39225262, 1843533.31000687 5744550.30713888, 1843537.21089892 5744550.47075254, 1843541.06965155 5744549.87791897, 1843544.74116062 5744548.55148175, 1843548.0862959 5744546.53930455, 1843549.53359801 5744545.22929443, 1844144.05575353 5744006.88500424, 1844169.18539025 5743983.5857433, 1844170.63172801 5743982.24570703, 1844172.94368956 5743979.05168963, 1844174.58874644 5743975.46769333, 1844175.50270343 5743971.63171704, 1844175.57703662 5743969.66175839, 1844175.90023907 5743961.04656371, 1844175.97457214 5743959.07660504, 1844175.5375125 5743956.34865246, 1844175.73760702 5743956.35989003, 1844177.73678424 5743956.27215751, 1844179.71618148 5743955.98629701, 1844181.65778673 5743955.50428874, 1844183.54258396 5743954.83111332, 1844185.34955492 5743953.97274958, 1844187.06267936 5743952.93918428, 1844188.66293657 5743951.73940016, 1844189.4001205 5743951.0628946, 1844199.50135086 5743941.78666567, 1844213.84039117 5743928.61827538, 1844215.28972002 5743927.28724656, 1844217.61466838 5743924.11025168, 1844219.27671508 5743920.54228211, 1844219.35211419 5743920.23420591, 1844219.64432342 5743920.18952037, 1844223.35289272 5743918.83709466, 1844226.72609487 5743916.78591001, 1844228.17943055 5743915.45088351, 1844242.51647028 5743902.28248667, 1844253.4640615 5743892.22881894, 1844254.21126251 5743891.54231917, 1844255.55975269 5743890.02607475, 1844256.74730665 5743888.38057548, 1844257.7628975 5743886.62381815, 1844258.59449784 5743884.7737984, 1844259.23508291 5743882.84851766, 1844259.67862504 5743880.86898012, 1844259.91909887 5743878.85418888, 1844259.93628859 5743877.83967025, 1844259.97595609 5743875.56550898, 1844263.40172796 5743875.62750567, 1844265.30771411 5743875.66172916, 1844269.06349335 5743875.01072919, 1844272.62898191 5743873.66213868, 1844275.87505338 5743871.66483413, 1844277.28130799 5743870.37777789, 1844293.26093854 5743855.74349582, 1844293.42794675 5743855.81372633, 1844297.16404668 5743856.59746499, 1844300.98202765 5743856.66191644, 1844304.74282077 5743856.00191699, 1844308.31032266 5743854.64332287, 1844311.55740795 5743852.63501293, 1844312.96166863 5743851.34195079, 1844366.48183378 5743802.05767893, 1844367.94418863 5743800.71065451, 1844370.28118872 5743797.49464845, 1844371.94128574 5743793.88164838, 1844372.85727827 5743790.01365209, 1844372.92562613 5743788.02667511, 1844372.99397396 5743786.03969812, 1844372.34618617 5743782.11786455, 1844370.93975308 5743778.39926161, 1844368.82953432 5743775.03003047, 1844367.46347793 5743773.58568301, 1844311.37120972 5743714.28931765, 1844598.56152946 5743510.53102903, 1844599.82925634 5743509.63101582, 1844602.05797441 5743507.46143768, 1844603.92386625 5743504.97427061, 1844605.3828408 5743502.22749453, 1844606.40080074 5743499.28910624, 1844606.95165187 5743496.22811234, 1844607.02330055 5743493.11953884, 1844606.61466136 5743490.03642345, 1844606.1741564 5743488.54511938, 1844558.82589522 5743328.15393844, 1844545.72733704 5743226.88587176, 1844545.50322096 5743225.15769254, 1844544.46552075 5743221.83172273, 1844542.86925421 5743218.73523003, 1844540.76133973 5743215.96031771, 1844539.4830261 5743214.77621074, 1844471.09777847 5743151.40250573, 1844439.20618072 5743078.48089337, 1844438.77908038 5743077.50588234, 1844437.72365546 5743075.65568148, 1844436.47798437 5743073.92932726, 1844435.05605492 5743072.34384485, 1844433.47485308 5743070.9192645, 1844431.75037123 5743069.6696121, 1844429.90260273 5743068.60991869, 1844427.95354434 5743067.75321654, 1844426.93937208 5743067.42987565, 1844347.35981 5743042.11069952, 1844087.70346261 5742812.08654871, 1844086.51504258 5742811.03362263, 1844083.8365753 5742809.32963639, 1844080.92346809 5742808.06961547, 1844077.84672431 5742807.28365755, 1844074.68536083 5742806.99386527, 1844071.51841542 5742807.20433173, 1844068.42393221 5742807.91314573, 1844065.47897565 5742809.10038539, 1844064.11929846 5742809.91825389, 1843510.54101528 5743142.92357374, 1843508.86995706 5743143.92917723, 1843505.97737608 5743146.54822255, 1843503.64650513 5743149.67618338, 1843501.9625264 5743153.19509576, 1843500.99062767 5743156.97296537, 1843500.76599237 5743160.86775796, 1843501.29879528 5743164.7334084, 1843502.56719526 5743168.42281405, 1843503.54576196 5743170.10983084))") },
        new MattShape { MattShapeId = 2, GeoShape = DbGeometry.FromText("POLYGON ((1767189.79377487 5904558.30070561, 1767215.1492355 5904492.43152391, 1767215.22475214 5904445.62448443, 1767192.95192382 5904443.13290794, 1767196.09833442 5904422.95242129, 1767174.81164464 5904414.75687878, 1767129.42429366 5904534.9388636, 1767189.79377487 5904558.30070561))") }
        );

        context.SaveChanges();
    }
}
Wrappers
public class TestDbProviderServices : DbProviderServices
{
    private DbProviderServices InnerProviderServices { get; set; }

    public TestDbProviderServices(DbProviderServices inner)
    {
        InnerProviderServices = inner;
    }

    protected override DbCommandDefinition CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
    {
        return InnerProviderServices.CreateCommandDefinition(providerManifest, commandTree);
    }

    protected override string GetDbProviderManifestToken(DbConnection connection)
    {
        return InnerProviderServices.GetProviderManifestToken(connection);
    }

    protected override DbProviderManifest GetDbProviderManifest(string manifestToken)
    {
        return InnerProviderServices.GetProviderManifest(manifestToken);
    }

    protected override DbSpatialDataReader GetDbSpatialDataReader(DbDataReader fromReader, string manifestToken)
    {
        return InnerProviderServices.GetSpatialDataReader(fromReader, manifestToken);
    }
}

public class TestDbConnectionFactory : IDbConnectionFactory
{
    private IDbConnectionFactory InnerDbConnectionFactory { get; set; }

    public TestDbConnectionFactory(IDbConnectionFactory inner)
    {
        InnerDbConnectionFactory = inner;
    }

    public DbConnection CreateConnection(string nameOrConnectionString)
    {
        return InnerDbConnectionFactory.CreateConnection(nameOrConnectionString);
    }
}
Test Console App
class Program
{
    static void Main(string[] args)
    {
        DbConfiguration.Loaded += (_, a) =>
        {
            a.ReplaceService<DbProviderServices>((s, k) => new TestDbProviderServices(s));
            a.ReplaceService<IDbConnectionFactory>((s, k) => new TestDbConnectionFactory(s));
        };

        var db = new TestEF6DataSource();
        var point = CreatePoint(1843503.54576196, 5743170.10983084);
        var shapes = db.MattShapes.Where(s => s.GeoShape.Intersects(point)).Select(s => s.MattShapeId).ToList();

        foreach (var shape in shapes)
        {
            System.Console.WriteLine(shape);
        }

        System.Console.ReadKey();
    }

    private static DbGeometry CreatePoint(double x, double y)
    {
        var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", x, y);
        return DbGeometry.PointFromText(text, 0);
    }
}

New Post: Multi-tenancy and connection pool

$
0
0
Exposing the baseConnection.StateChange events in XDConnection might help to resolve the "The connection is not open." exception thrown on SaveChanges, e.g.:
public override event StateChangeEventHandler StateChange {
    add {
        this._baseConnection.StateChange += value;
    }
    remove {
        this._baseConnection.StateChange -= value;
    }
}

New Post: Multi-tenancy and connection pool

$
0
0
@snowgon - this was indeed the problem here - it was resolved here

New Post: EF 6, Self-Tracking Entities

New Post: What UseLegacyProvider=True means

$
0
0
I switched my project to Entity Framework v6. When I Updated Model from Database, EF Designer included this element in EDMX:
<DesignerProperty Name="UseLegacyProvider" Value="True" />
What it means? And why is it True?

New Post: EF6 support for ASP.NET WebForms EntityDataSource

$
0
0
Hi Diego,

Is there any targeted date for a release of the EntityDataSource build EF6 compatibable version?

I really need it !

Thanks.

New Post: "MappingViewCacheFactory is already set and cannot be modified"

$
0
0
if I create a context which is created in child threads ( no sharing across threads ), I get the following error "MappingViewCacheFactory is already set and cannot be modified".

If I make sure I create the context 1 time before making the child threads than it works fine.

again I stress I am not sharing a context across threads, it is being newed in each thread.

New Post: "MappingViewCacheFactory is already set and cannot be modified"

$
0
0
The issue seems to be caused by a race condition in the code that initializes the mapping view cache factory and we are working on fixing it for EF 6.0.2. Workitem 1843 will track this work.

New Post: "MappingViewCacheFactory is already set and cannot be modified"

$
0
0
Is SotrageMappingItemCollection.MappingViewCacheFactory set explicitly or is the code using DbMappingViewCacheTypeAttribute to specify the mapping view cache?

New Post: Namespace is changed when moving EDMX file to another folder

$
0
0
This is REALLY annoying glitch (full video - http://sdrv.ms/HUi7m5). Say, I have generated some model. The file is called "TestModel.edmx". Then, I begin creating code:
namespace TestEF
{
   async private void OnGetData(object sender, RoutedEventArgs e)
   {
       using(TestEntities db = new TestEntities())
       {
           await db.T1.LoadAsync();
           dg.ItemsSource = db.T1.Local; //dg - DataGrid
       }
   }
}
All is well and good. But after some time I have decided to create folder in project named "Database" and move this EDMX file to this folder. And...error appears:

The type or namespace name 'TestEntities' could not be found (are you missing a using directive or an assembly reference?)

Whatta??? My "TestEF" namespace for T1 class has been changed to "TestEF.Database"! In other words, VS appended the folder name to namespace. And because of it I have to change the namespace in each and every source code file! What if I have 300 files where I use this namespace?

Is it cool feature or I don't understand something?

New Post: SQL Server Compact 3.5 provider for EF6

$
0
0
Hi Team, I have heard a few requests for a SQL Server Compact 3.5 provider for EF6 - how do you feel about me adding that to the codebase? (Only minor changes to the 4,0 provider are required as far as I can see)

New Post: Multiple contexts per db and automatic migration

$
0
0
In my current project I use one db for different contexts using HasDefaultSchema. All contexts have a custom initializer, that automatically migrates to the newest version using Database.CompatibleWithModel(), DbMigrator.Update() and a configuration that has AutomaticMigrationsEnabled set to true.

Two things are unclear to me:

Initial DbMigration

The first Add-Migration for each contexts contains the complete model - as expected. Accessing the contexts for the first time calls the initializer and updates the db correctly using the specified schemas. From this point on, automatic migrations are applied correctly for all contexts/schemas. Without an initial Add-Migration the migrator fails to insert any table, even if the db is empty.

The documentation says:
"However, for implementation reasons, transferring the __MigrationHistory table to a different schema can only occur using a code-based migration."

So, why does migrations refuse to automatically update an empty db without an initial DbMigration, but adds tables of an other context/schema to a db, that already contains tables of another context/schema (with an initial code-based migration)? The expected behavior was, that without any added DbMigration the complete model gets added to an empty db, where no schema transferring should be neccessary.

DbMigration discovery

Not having read the source code of ef much, it's hard to know how DbMigrations are discovered. I implemented a custom initializer to do automatic migration, because my connection string names are only known at runtime (one db per tenant).

When using DbMigrationsConfiguration<TContext> only to enable automatic migrations,the custom initializer could be simplified by just creating a generic configuration for the context at runtime, enable automatic migrations and supply it to the DbMigrator.

If I don't use a derived configuration class in the same assembly as the migrations, the initial DbMigration can not be found (in the assembly of the context) and the update fails. Is there a way to tell DbMigrator where the DbMigrations live without implementing a configuration?

Thanks in advance
mat

New Post: What UseLegacyProvider=True means

$
0
0
This property is added when you are using the Entity Framework 6 Tools for Visual Studio with an EDMX file that is for a project that targets Entity Framework 1-5. Its only affect is that, at design-time, the "legacy" (EF 1-5) provider is used for database interactions. It has no runtime affect.

If your project targets Entity Framework 6, this property may have been added in error. If so, would you mind filing a bug with the steps you took that caused this?

New Post: Multiple contexts per db and automatic migration

$
0
0
Hi mat,

I think you might need to take a look (and set the correct values for) the following DbMigrationsConfiguration properties:

1) MigrationsNamespace/MigrationsAssembly - this is how to specify the location of the indivual DbMigrations classes.
2) ContextKey - When using multiple contexts per database, this property is used as a secondary key when accessing the __MigrationHistory table. Normally, the default context key is fine because it is the type name of the derived migrations config. However, if there is no derived config then you will want to explicitly set it to something unique per context. i.e. The type name of the context.

Let me know if this helps.
  • Andrew.
Viewing all 1793 articles
Browse latest View live


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