code-first

Dropping table In Entity Framework Core and UWP

ぐ巨炮叔叔 提交于 2019-12-12 04:58:58
问题 I am learning Entity Framework with UWP. I tried dropping a table by deleting it from DbContext. When running the code after migration I received an error that dropping primary key is not supported with UWP. This article, https://docs.efproject.net/en/latest/providers/sqlite/limitations.html, recommends using sql(string) method. This article, https://msdn.microsoft.com/en-us/data/jj592907.aspx, has an example I am trying to follow. using (var context = new BloggingContext()) { var blogs =

Entity Framework Code First Many-To-Many with shared elements

ε祈祈猫儿з 提交于 2019-12-12 04:17:55
问题 I need to create a many-to-many table relationship in which the elements of one table are shared by the elements of a second table. I've read the multitude of similar posts, but I'm clearly still wrong somewhere. I've reduced my problem to this simple example. I have two tables: Beverages and Ingredients. I want the Ingredients to be shared among the Beverages. Is the problem how I've created the bridge table? (Can I do without a bridge table?) Or is the problem in how I'm managing the data

How to ignore validation annotation if field is blank?

孤人 提交于 2019-12-12 02:56:11
问题 I have these classes: Class Parent { [Required] String Name ; Child child ; } Class Child { [Required] Child FirstName ; [Required] Child LastName ; } I have a form showing the Parent entity fields including the Childs's. With my configuration the child's FistName and LastName are required and if left blank causes validation to fail. What I need is have validation pass if both the child's FirstName and LastName are submitted blank. If either FirstName or LastName is submitted then the other

Entity Framework Code First - Tests Overlapping Each Other

假如想象 提交于 2019-12-12 02:52:57
问题 My integration tests are use a live DB that's generated using the EF initalizers. When I run the tests individually they run as expected. However when I run them all at once, I get a lot of failed tests. I appear to have some overlapping going on. For example, I have two tests that use the same setup method. This setup method builds & populates the DB. Both tests perform the same test ACT which adds a handful of items to the DB (the same items), but what's unique is each test is looking for

Entity Framework code first migration giving SqlException: “There is already an object named 'TableName' in the database.”

会有一股神秘感。 提交于 2019-12-12 02:32:33
问题 I am using Entity Framework 6.3 for an MVC 5 application, using code-first (for the first time) with SQL Server 2012. The Database does not exist before hand, it is all being created from scratch by EF. When I attempt to start the application, and hence EF should create the database, it's giving me the following SqlException error message: "There is already an object named 'TableName' in the database." I have in my project the following very basic Entity: [Table("TableName")] public class

Configuring multiple 1 to 0..1 relationships between tables entity framework

て烟熏妆下的殇ゞ 提交于 2019-12-12 02:32:29
问题 Following on from earlier posts today: Entity framework one to zero or one relationship without navigation property Understanding ForeignKey attribute in entity framework code first I'm now trying to configure the following relationships: Item1 has optional RawData Item2 has optional RawData Item3 has optional RawData RawData must be attached to either Item1, Item2 or Item3 - it would not be expected to exist on its own. Current structure is: class ItemX { [Key] public int Id { get; set; }

Entity Framework CTP 5 RelatedTo Attribute not working

﹥>﹥吖頭↗ 提交于 2019-12-12 01:48:22
问题 Using Entity Framework CTP 5 I am trying to make a list of foreign keys in my class. But I keep getting an error which says RelatedTo can not be found. Here is the code: public class VertragsVerweis : GenericBLL { [Key] public String Uid { get; set; } public String VertagsVerweisNr { get; set; } public String Bezeichnung { get; set; } public Boolean Reparatur { get; set; } [RelatedTo(RelatedProperty="Artikel")] public List<Artikel> Artikelen { get; set; } } This gives me the error: Error 2

Multiple string connections in EF DbContext

 ̄綄美尐妖づ 提交于 2019-12-12 01:33:13
问题 I’m developing a MVC Website based in codeplex EFMVC solution, and I’m using Entity Framework and Repository, Unit of Work and Command Patterns. My website needs to be a SaaS solution (software as a service) multiple database. In my legacy Asp.Net WebForms I have a XML file that holds all the different string connections and I’m trying to use the same strategy. So in my LoginController I create a command that has company (to identify in which database will be connected) username and password.

Can't get property names working with foreign keys in Code First

我只是一个虾纸丫 提交于 2019-12-11 21:41:35
问题 I have been supplied a DB, and I need to get Code First set up for it. I think I'm mostly done, the problem that I'm running into right now is I want to change some of the foreign key names in the entities to make a little more sense. Let's say I have two tables, Person and Location, that look like this: Person ------ PersonId int not null (PK) DefaultLocation int not null (FK) Location -------- LocationId int not null (PK) For the location entity, I think I've got it: public class Location {

Code first approach versus database first approach

孤者浪人 提交于 2019-12-11 15:33:01
问题 I am working on an asp.net MVC 3 web application and I am using database first, but after I have mapped the DB tables into entity classes using entity framework, I am interacting with these tables as I will be interacting on the code first approach by dealing with Database tables as classes an objects. So after mapping the tables into entity classes I find that the code first approach and DB first are very similar but except of start writing the entities classes from scratch (as in code first