ef-code-first

file cannot be loaded because the execution of scripts is disabled on this system

孤人 提交于 2019-12-20 02:04:12
问题 File C:\Users\Acer\Desktop\Projelerim\BEM_CANLI\BEM\packages\EntityFramework.5. 0.0\tools\init.ps1 cannot be loaded because its execution is blocked by softwar e restriction policies. For more information, contact your system administrator. At line:1 char:44 + $__pc_args=@(); $input|%{$__pc_args+=$_}; & <<<< 'C:\Users\Acer\Desktop\Proj elerim\BEM_CANLI\BEM\packages\EntityFramework.5.0.0\tools\init.ps1' $__pc_args[ 0] $__pc_args[1] $__pc_args[2]; Remove-Variable __pc_args -Scope 0 +

Super simple implementation of multiselect list box in Edit view

六眼飞鱼酱① 提交于 2019-12-20 01:38:17
问题 Using MVC4 here with EF and CF (badly) I have a class like this: public class Feature { public int ID { get; set; } public string Desc { get; set; } } And one like this: public class Device //change to Devices { public int ID { get; set; } public string Name { get; set; } public virtual ICollection<Feature> Features { get; set; } } On the Edit view for the Device model I would like for there to be a ListBox that contains all elements of the Feature model (Desc property displayed) with those

Deleting in EF Code first causes navigational properties to be set to null and empty

本秂侑毒 提交于 2019-12-20 01:13:37
问题 I noticed something interesting when I was performing a delete using EF code first. I use the following domain model: public class User { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual ICollection<Playlist> Playlists { get; set; } } public class Playlist { public virtual long Id { get; set; } public virtual string Title { get; set; } public virtual User User { get; set; } public virtual ICollection<Track> Tracks { get; set; } } public class Track

entity framework custom data type mapping

岁酱吖の 提交于 2019-12-20 01:07:28
问题 Given this code: public class Car { public virtual int CarId { get; set; } public virtual string TypeName { get; set; } public ConvertableNullable<double> Price { get; set; } } Where the ConvertableNullable is just a workaround to Nullable , but it doesn't inherit from it. Now, this my simple context, where i map, the car class to entity, and map every property of it public class MyDBContext : DbContext { public MyDBContext() : base( "data source=.;initial catalog=newDB1;integrated security

The key component 'Id' is not a declared property on type 'TypeName', when using base class and private setter

允我心安 提交于 2019-12-19 21:46:50
问题 I want to use an abstract base class for entities, which is not mapped on any table: public abstract class Entity { public virtual int Id { get; private set; } } Since Id will be auto-increment, I don't want to allow to change this property from outside. Hence, its setter is private . Here's a sample entity type: public class Order : Entity { public virtual string Customer { get; set; } } ...configuration types: public class EntityConfiguration<TEntity> : EntityTypeConfiguration<TEntity>

IValidatableObject is useless for EF navigation properties?

走远了吗. 提交于 2019-12-19 11:56:14
问题 IValidatableObject.Validate only gets called when the implementing entities DbEntityEntry.State differs from "Unchanged". And just changing a navigation property won't change the state and so the validation will never occur. Why Microsoft always releases half-baked beta things? I cannot even detect the navigation property change by hand: var changes = context.ChangeTracker.Entries() .Where(e => e.State != EntityState.Unchanged) .ToArray(); Returns an empty array. 回答1: There are a few

How to seed identity seed value in entity framework code first for several tables

南楼画角 提交于 2019-12-19 10:54:56
问题 I have seen this and this . I simply wish to seed the start value for ID columns for my code first ( EF6.1) tables. Now I can do this public class CustomInitializer : CreateDatabaseIfNotExists<FormsDbContext> { protected override void Seed(FormsDbContext context) { context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('MyTable', RESEED, 1000)"); } } But as I have lots and lots of tables, I find it odd ( and it feels almost wrong) that I would have to repeat the above line for ALL of those. I

Eagerly Load Navigation Property that is List<OfSomeBaseClass>

不想你离开。 提交于 2019-12-19 10:26:32
问题 Using EF Code First and given an Entity that contains a List, how can I eagerly load the entire object graph for that entity: Example: public class Foo { public int Id { get; set; } public List<BarBase> Bars { get; set; } } public class BarBase { public int Id { get; set; } public string Text { get; set; } } public class BarTypeA : BarBase { public List<Baz> Bazes { get; set; } } public class BarTypeB : BarBase { public List<Quux> Quuces { get; set; } { get; set; } } If BarBase were not a

EF Code First Fluent API - lowercase first letters of all columns

旧城冷巷雨未停 提交于 2019-12-19 09:53:17
问题 I'm hoping to set up an EF Code First convention where all of the column names of the properties have a lowercase first letter. However, I have other fluent API code that changes column names from the default. I can't seem to find a way to get access to the current column name of a property in order to lowercase the first letter. Starting with the PropertyInfo, as in modelBuilder.Properties() is not enough because the column name may have already been set to be different than the member name.

EF 4.1 Code First Multiple Result Sets

五迷三道 提交于 2019-12-19 07:17:11
问题 I need to execute a Raw SQL query that returns multiple result sets. Is that possible in EF CF ? Thanks! 回答1: Description Yes you can! ;) You can perform a raw sql query using DbCommand in Entity Framework Code First too. You can perform queries with multiple result sets and jump to the next result set using NextResult() method of the SqlDataReader class. Sample namespace MyNamespace { public class MyDbContext : DbContext { } public class Test { public void Test() { MyDbContext context = new