entity-framework

X Already contains a definition Y with EntityFramework? (simple database)

让人想犯罪 __ 提交于 2020-02-11 06:27:07
问题 I have 3 tables in my MS SQL database and I have added a EntityFramework(latest) to my project where I have imported these 3 tables. The first problem was that no Entities was built so I changed "Code Genereation Strategy" from None to Default . After build I get X Already Contains a definition for Y on all properties of the entities. When looking closer it have generated a partial ex Users.cs and one partial User in in the MainModel.Designer.cs ? Why is it generating User.cs ? I have a

Entity Framework : Why this code doesn't work

﹥>﹥吖頭↗ 提交于 2020-02-08 09:39:45
问题 I'm using Entity Framework 6.0, DbContext. I'm using this method to copy an object and some related children: Imports System.Data.Objects Imports System.Data.Objects.DataClasses Imports System.Runtime.CompilerServices Public Module Entities <Extension()> Public Function CloneEntity(Of T As Class)(entity As T, context As ObjectContext, Optional include As List(Of IncludeEntity) = Nothing, Optional copyKeys As Boolean = False) As T Return CloneEntityHelper(entity, context, include, copyKeys)

Entity Framework : Why this code doesn't work

我怕爱的太早我们不能终老 提交于 2020-02-08 09:39:28
问题 I'm using Entity Framework 6.0, DbContext. I'm using this method to copy an object and some related children: Imports System.Data.Objects Imports System.Data.Objects.DataClasses Imports System.Runtime.CompilerServices Public Module Entities <Extension()> Public Function CloneEntity(Of T As Class)(entity As T, context As ObjectContext, Optional include As List(Of IncludeEntity) = Nothing, Optional copyKeys As Boolean = False) As T Return CloneEntityHelper(entity, context, include, copyKeys)

EF Reverse Engineer Code First does not populate one-to-many & many-to-many properties

主宰稳场 提交于 2020-02-08 09:38:48
问题 I'm not sure if I'm doing things wrong or EF has a bug. I followed this StackOverflow post but to my avail, it still failed to populate. The structure is basically the same. I'm absolutely sure on the data since the keys match up to the data. Eventually, I ended up just manipulating the models in my Service layer just to populate the properties. public TeamsService(IRepositoryAsync<Team> repo, IRepositoryAsync<AspNetUser> userRepo) : base(repo) { _repo = repo; _userRepo = userRepo; } public

The class 'X' was not found in the chain configured namespaces … when I try a multiple connection with doctrine

荒凉一梦 提交于 2020-02-08 07:41:23
问题 So I know this is another "class X not found in namespace" but I can't find an answer to my senario: I have a class "temp" (pretty name) that looks like that : namespace DbBccCrawlBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * * @ORM\Entity * @ORM\Table(name="temp") * */ class Temp { /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; and the orm in config.yml : orm: auto_generate_proxy

Entity Framework dbSet.Add when classes linked

烈酒焚心 提交于 2020-02-08 06:29:46
问题 Question : Why doesn't the dbSet.Add method work when I'm attempting to add an object that's linked to other objects in EF? Details : Some background on this: I'm a beginner with EF, and I'm learning how to use Code First to develop the data model. I'm using VS2013 Express, with Entity Framework 6 added through NuGet to a basic MVC project. I've created three classes for my data model: Class_oneOnly , Class_many , and Class_several . Class_oneOnly has a one-to-many relationship to the other

Entity Framework dbSet.Add when classes linked

橙三吉。 提交于 2020-02-08 06:29:34
问题 Question : Why doesn't the dbSet.Add method work when I'm attempting to add an object that's linked to other objects in EF? Details : Some background on this: I'm a beginner with EF, and I'm learning how to use Code First to develop the data model. I'm using VS2013 Express, with Entity Framework 6 added through NuGet to a basic MVC project. I've created three classes for my data model: Class_oneOnly , Class_many , and Class_several . Class_oneOnly has a one-to-many relationship to the other

Standardizing and Abstracting IQueryable construction with Linq to Entities

十年热恋 提交于 2020-02-08 05:48:24
问题 TL;DR; What is the best way to standardize and abstract IQueryable construction in large data access layers? Are extensions acceptable or encouraged? Background We're using Entity Framework 6 with a Repository pattern as our Data Access Layer. In order to make our data calls more efficient, we've recently started using some structured Data Transfer Objects to force ourselves to only pull from the database what is necessary. For example: We have a dashboard that uses 15 of 500 properties of an

The property 'PK' is part of the object's key information and cannot be modified. Error occurs after some successful data entry

你离开我真会死。 提交于 2020-02-08 04:13:38
问题 I have checked other posts with the related error but in my case it is different since it successfully allows first iteration and occurs in the second iteration of the loop. I am using DataBase first approach in MVC application. In the following code: ACOD a = new ACOD(); int cd = 1; foreach (var t in e) { a.S1 = t.S1; a.S2 = t.S2; a.S39 = t.S39; a.S40 = t.S40; if (db.ACODs.ToList().Count != 0) { var td = db.ACODs.Max(x => x.N100); cd = Convert.ToInt32(td) + 1; } a.N100 = cd; db.ACODs.Add(a);

The property 'PK' is part of the object's key information and cannot be modified. Error occurs after some successful data entry

拥有回忆 提交于 2020-02-08 04:13:25
问题 I have checked other posts with the related error but in my case it is different since it successfully allows first iteration and occurs in the second iteration of the loop. I am using DataBase first approach in MVC application. In the following code: ACOD a = new ACOD(); int cd = 1; foreach (var t in e) { a.S1 = t.S1; a.S2 = t.S2; a.S39 = t.S39; a.S40 = t.S40; if (db.ACODs.ToList().Count != 0) { var td = db.ACODs.Max(x => x.N100); cd = Convert.ToInt32(td) + 1; } a.N100 = cd; db.ACODs.Add(a);