entity-framework

Tell EF to automatically compute and insert the current date time when the row is created?

本秂侑毒 提交于 2020-01-25 04:20:06
问题 I want to insert current Datetime when ever a new row is inserted. I am using Code First Approach of EF 6,MVC 5 After searching I got this [DatabaseGenerated(DatabaseGeneratedOption.Computed)] public DateTime? CreatedDate { get; set; } It has to be written in Models Class,but when ever a new record is inserted NULL is saved in DB,I have noticed that this is just declaration of CreatedDate,where to write CreatedDate = DateTime.Now OR any other way to solve it. My Entire Model namespace

One to one relationship with FK in one direction

痞子三分冷 提交于 2020-01-25 04:19:15
问题 How do I get the following relationship to only generate the FK in Entity2? public class Entity1 { public int Id { get; set; } public virtual Entity2 Entity2 { get; set; } } public class Entity2 { public int Id { get; set; } public int? Entity1Id { get; set; } public virtual Entity1 Entity1 { get; set; } } I want Entity1 be able to get a reference to an Entity2 (have EF lazy load it), but I don't want Entity1 to have an FK to Entity2 in the db, I just want Entity2 to have an FK to Entity1. Is

Symfony Doctrine Many to Many insert

风流意气都作罢 提交于 2020-01-25 03:44:08
问题 I have a problem with my entities and controllers in Symfony. I would insert on my DB value in a many to many table generated. Entity Requests with only many to many elements class Requests { /** * @ORM\ManyToMany(targetEntity="Tipi", inversedBy="requests") * @ORM\JoinTable(name="tipi_richieste") */ private $tipi; public function __construct() { $this->tipi = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Add tipi * * @param \AppBundle\Entity\Tipi $tipi * * @return Requests */

Can I specify child entity default ordering with Entity Framework Code First?

▼魔方 西西 提交于 2020-01-25 03:20:42
问题 For example, with the following classes public class Child { public Guid Id { get; set; } public String Description { get; set; } public double Value { get; set; } public Child() { Id = Guid.NewGuid(); } } public class Parent { public Guid Id { get; set; } public String Name { get; set; } public virtual IList<Child> Children { get; set; } public Parent() { Id = Guid.NewGuid(); Children = new List<Child>(); } } And context public class TempContext : DbContext { public DbSet<Child> Children {

Getting ORA-00932: inconsistent datatypes: expected - got CLOB with Database First in .net

。_饼干妹妹 提交于 2020-01-25 02:50:29
问题 So I am using EF database first on an oracle db. I am getting the above error when I do this in my code: contractType.CLIENT_TYPE != null && contractType.CLIENT_TYPE.ToUpper() == "POL" That column is defined as VARCHAR2(10 BYTE) in Oracle and the .net type is string. Did a lot of searching and no one really mentions this error in the context of .net. Hoping someone might have an idea. 回答1: So I figured out a solution to this. I was using Odp.net version 11. Apparently this is a bug with

LINQ dynamic property in select

我的未来我决定 提交于 2020-01-25 02:00:06
问题 // Hi everyone i do this call in Action : [HttpGet] public virtual ActionResult JsonGetProvinces(int countryId) { //WebSiteContext WbContext = new WebSiteContext(); //UnitOfWork UnitofWork = new UnitOfWork(WbContext); var provinces = ( from province in unitofWork.ProvinceRepository.All where province.CountryId == countryId select new { Id = province.Id, Name = province.GetType().GetProperty("Name_" + CultureManager.GetCurrentCultureShortName()).GetValue(province) } ).ToList(); return Json

Unable to register DbConnection with Unity and Entity Framework

旧巷老猫 提交于 2020-01-25 01:07:45
问题 I am not at all sure what the underlying problem is that is causing this exception. I am using ASP.NET MVC, with Unity.Mvc, and Entity Framework 6. I have the following code to register my repositories: public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your types here // container

Unable to register DbConnection with Unity and Entity Framework

不羁的心 提交于 2020-01-25 01:07:10
问题 I am not at all sure what the underlying problem is that is causing this exception. I am using ASP.NET MVC, with Unity.Mvc, and Entity Framework 6. I have the following code to register my repositories: public static void RegisterTypes(IUnityContainer container) { // NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. // container.LoadConfiguration(); // TODO: Register your types here // container

Does Breeze work with Table Per Hierarchy (TPH)

廉价感情. 提交于 2020-01-25 00:38:06
问题 I'm trying to plug BreezeJs into an existing datastructure and getting an error in the meta data fetch. I can replicate this by adding the following to the CarBones sample namespace CarBones.Models { public abstract class VanBase { public int Id { get; set; } public string Manufacturer { get; set; } public int Wheels { get; set; } } public class BasicVan : VanBase { } public class LiveriedVan : VanBase { public string Livery { get; set; } } } then in the context public DbSet<VanBase> Vans {

hottowel nuget with entity framework 6?

让人想犯罪 __ 提交于 2020-01-25 00:32:06
问题 I'm trying to get hottowel installed via nuget in my german visual studio 2013 mvc application. I get this error: Install-Package : Error during the update from "EntityFramework 6.0.1" auf "EntityFramework 5.0.0". No version of "EntityFramework.de, Microsoft.AspNet.Identity.EntityFramework" found, which are compatible with "EntityFramework 5.0.0" It just says, that the new authentication thing called "identity" uses entityframework features which are not compatible with the needed entity