Entity Framework loading child collection with sort order

You cannot achieve it directly because neither eager or lazy loading in EF supports ordering or filtering. Your options are: Sort data in your application after you load them from database Execute separate query to load child records. Once you use separate query you can use OrderBy The second option can be used with explicit … Read more

How to configure ProviderManifestToken for EF Code First

If you’re using EF 6 (just released) you have an alternative. Dependency Resolution You can use the new dependency resolution feature to register an implementation of IManifestTokenResolver (described in this preview documentation as IManifestTokenService). This article gives a bit more information on how to use DbConfiguration. The easiest way to use it is like this: … Read more

Entity Framework DateTime and UTC

Here is one approach you might consider: First, define this following attribute: [AttributeUsage(AttributeTargets.Property)] public class DateTimeKindAttribute : Attribute { private readonly DateTimeKind _kind; public DateTimeKindAttribute(DateTimeKind kind) { _kind = kind; } public DateTimeKind Kind { get { return _kind; } } public static void Apply(object entity) { if (entity == null) return; var properties = … Read more

Code First Migration with Connection Strings

On the package manager console type: Get-Help Update-Database Relevant part: Update-Database [-SourceMigration <String>] [-TargetMigration <String>] [-Script] [-Force] [-ProjectName <String>] [-StartUpProjectName <String>] [-ConfigurationTypeName <String>] [-ConnectionStringName <String>] [<Com monParameters>] So you can do a Update-Database -ConnectionStringName “MyConnectionString” and it should work like a charm. You also have a MigrateDatabaseToLatestVersion database initializer, if you set it (via Database.SetInitializer()), … Read more

How to run Seed() method of Configuration class of migrations

Answering your first question. Create a Migration by running add-migration SeedOnly Clear out all Up() and Down() code generated if there was any pending changes public partial class SeedOnly : DbMigration { public override void Up() { } public override void Down() { } } Then you can Target a Specific Migration by running update-database … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)