ef-code-first

Entity Framework Null Reference Exception

折月煮酒 提交于 2020-01-06 09:06:35
问题 I am trying to grasp EF Code First but I still do not get how to access the referenced objects from another class (due to lack of enough knowledge, I cannot even formulate the question). Here's what my simple code looks like: public class Destination { public int DestinationId { get; set; } public string Name { get; set; } public string Country { get; set; } public string Description { get; set; } public byte[] Photo { get; set; } public List<Lodging> Lodgings { get; set; } } public class

Entity Framework Null Reference Exception

旧街凉风 提交于 2020-01-06 09:05:16
问题 I am trying to grasp EF Code First but I still do not get how to access the referenced objects from another class (due to lack of enough knowledge, I cannot even formulate the question). Here's what my simple code looks like: public class Destination { public int DestinationId { get; set; } public string Name { get; set; } public string Country { get; set; } public string Description { get; set; } public byte[] Photo { get; set; } public List<Lodging> Lodgings { get; set; } } public class

Error Seeding Database? (MVC 4 Application, EF 5, Code-First)

孤人 提交于 2020-01-06 08:27:12
问题 I've successfully added a new migration in my project, but when I run update-database in Package Manager Console I receive: Error Seeding Privileges: An error occurred while updating the entries. See the inner exception for details. . Full Details: PM> update-database Specify the '-Verbose' flag to view the SQL statements being applied to the target database. No pending explicit migrations. Running Seed method. System.Exception: Error Seeding Privileges: An error occurred while updating the

How to configure this one-to-zero-or-one relationship?

给你一囗甜甜゛ 提交于 2020-01-06 03:11:25
问题 I know there are some answered questions on SO about 1:0..1-relationships. I have looked at this and this, but don't think they apply to my question. I have these three (simplified) models in a CMS-system. public class FrontPageItem { public int Id { get; set; } public int ItemType { get; set; } // 1 = Article, 2 = WebPage, etc... public int? ArticleId { get; set; } public Article Article { get; set; } public int? WebPageId { get; set; } public WebPage WebPage { get; set; } } public class

Manually map POCO to existing Table using Entity Framework

馋奶兔 提交于 2020-01-06 01:53:07
问题 I have an existing database table Movie . Now I want to write a POCO Movie.cs which will map to that table. I want to have control over the mapping partially because I'm trying to learn more about EF. The Movie table has 3 fields: Title VARCHAR(255,), ReleaseDate DATETIME, Price MONEY . What would my DbContext - derived class look like for this? Coming from a Java/Hibernate background, I figured I would just map fields in the POCO to cols in the table, but it doesn't seem that straight

Entity Framework code-first: querying a view with no primary key

帅比萌擦擦* 提交于 2020-01-06 01:29:12
问题 Our customer has given the access to views in which there is no primary key is defined. I know Entity Framework needs a primary key for table to identify. But for views not having primary key is it still possible to query. I try to find but always Entity Framework gives error saying: Error: : EntityType 'ViewWeight' has no key defined. Define the key for this EntityType. I understand key is important for tables, but for views just to read is there any hack or way to read the values without

Map a column to be IDENTITY in db

戏子无情 提交于 2020-01-05 16:32:42
问题 Although I have marked my ID column with .Identity() , the generated database schema doesn't have IDENTITY set to true, which gives me problems when I'm adding records. If I manually edit the database schema (in SQL Management Studio) to have the Id column marked IDENTITY , everything works as I want it - I just can't make EF do that by itself. This is my complete mapping: public class EntryConfiguration : EntityConfiguration<Entry> { public EntryConfiguration() { Property(e => e.Id)

About c# partial class accesibility

丶灬走出姿态 提交于 2020-01-05 13:53:26
问题 I have a question about partial classes in c# In This picture, I have a domain model. I am have added reference this(DomainModelLib) to Client application and repoistory application. Repository application is using this domain model classes as "DbSet" and getting data from database. Realtions are created in model partial classes as you can see. I referenced Model to Client application. I wanna first partial(first red frame) of Product class can access in Client application but second part

About c# partial class accesibility

僤鯓⒐⒋嵵緔 提交于 2020-01-05 13:53:25
问题 I have a question about partial classes in c# In This picture, I have a domain model. I am have added reference this(DomainModelLib) to Client application and repoistory application. Repository application is using this domain model classes as "DbSet" and getting data from database. Realtions are created in model partial classes as you can see. I referenced Model to Client application. I wanna first partial(first red frame) of Product class can access in Client application but second part

Code First - Retrieve and Update Record in a Transaction without Deadlocks

瘦欲@ 提交于 2020-01-05 10:24:41
问题 I have a EF code first context which represents a queue of jobs which a processing application can retrieve and run. These processing applications can be running on different machines but pointing at the same database. The context provides a method that returns a QueueItem if there is any work to do, or null, called CollectQueueItem . To ensure no two applications can pick up the same job, the collection takes place in a transaction with an ISOLATION LEVEL of REPEATABLE READ . This means that