entity-framework-5

User has roles for systems - how to (object-)model ternary relation?

佐手、 提交于 2019-11-28 12:03:08
问题 I've got the following Entities: Privilege ( Id, Name ) Role ( Id, Name, ICollection<Privilege> ) System ( Id, Name ) User ( Id, Name, Pass, ? ) Now I want to model "A user may have for each of zero or more systems zero or more roles", e.g.: IDictionary<System, ICollection<Role>> SystemRoles { get; set; } Is this possible with ASP.NET EntityFramework? If yes, how? What attributes do I have to set? Been looking around for quite some time now, however I don't find anything useful on the net for

Enable-Migrations installation error

眉间皱痕 提交于 2019-11-28 10:49:46
I'm running into a problem when enabling migrations on one of my projects. I execute Enable-Migrations command from the Nuget Console and receive an error saying: Exception calling "SetData" with "2" argument(s): "Type 'Microsoft.VisualStudio.TeamArchitect.ModelingProject.ModelProjectAutomationObject' in assembly 'Microsoft.VisualStudio.TeamArchitect.ModelingProject, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable." At D:\Solution\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:391 char:5 + $domain.SetData('startUpProject',

System.Data.Spatial DbGeography.Distance units?

爷,独闯天下 提交于 2019-11-28 10:42:53
When measuring the distance between two locations using the DbGeography.Distance(otherLocation) what is the unit of the distance? Even the msdn information and the intellisense fails to specify the unit of the distance. Anyone knows? [edit] I'm using srid 4326. which most examples seems to use. From what I can find, 4326 seems to be radians, this leaves me completely clueless. radians are used to measure angles/degrees so what does this mean in reality ? Sign Several articles seem to agree on meters being used in 4326 as the unit of distance. WGS 84 is done in meters as well, which is probably

Non-static method requires a target. Entity Framework 5 Code First

若如初见. 提交于 2019-11-28 10:39:30
I am getting the error "Non-static method requires a target." when I run the following query: var allPartners = DbContext.User .Include(u => u.Businesses) .Where(u => u.Businesses.Any(x => x.Id == currentBusinessId)) .ToList(); My entites are defines like this: public class User : Entity { public virtual List<Business> Businesses { get; set; } } public class Business : Entity { public virtual List<User> Users { get; set; } } public class Entity { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public Guid Id { get; set; } } And my context is configured like this; public class

how to get a list of all entities in EF 5?

帅比萌擦擦* 提交于 2019-11-28 10:32:44
问题 I am building an MVC 4 app. I have view that has a dropdown that needs to display all the tables (entities) used.. How can I do that? I am using EF 5 code first with configurations. Any help would be appreciated. Thanks 回答1: This code will get them for you, of course the ones that has been imported to your EDM which necessarily is not all the tables in your data store. var tableNames = context.MetadataWorkspace.GetItems(DataSpace.SSpace) .Select(t => t.Name) .ToList(); For code first: using

In what scenarios do I need foreign keys AND navigation properties in entity framework

你说的曾经没有我的故事 提交于 2019-11-28 09:58:54
My Order class has: public int CustomerId { get; set; } public Customer Customer { get; set; } Do I really need both properties to make a relation working? I am not using disconnected entities, I am using code first approach. Ying According to Julia Lerman's book: Programming Entity Framework: DbContext , the difference lies at the difficulty of updating the navigation property. In page 85, She suggests "If there is one thing you can do to make your life easier in N-Tier scenarios, it’s to expose foreign key properties for the relationships in your model." The book includes samples for both

Does Entity Framework 5 support unique constraints?

走远了吗. 提交于 2019-11-28 09:43:40
Wondering if Entity Framework 5 supports unique constraints on entity properties? If so, how can I specify that a property should be unique? No, it doesn't. There were plans in the past to include a unique constraint feature in EF 5.0: http://blogs.msdn.com/b/efdesign/archive/2011/03/09/unique-constraints-in-the-entity-framework.aspx But you can see that there is an update on top of the post: Update: this feature has been postponed and will not be included in Entity Framework 5. You can vote on the feature to raise possibly the priority it gets implemented with... http://data.uservoice.com

Loading all the children entities with entity framework

[亡魂溺海] 提交于 2019-11-28 07:26:40
I have a data model like this I would like to load all the related entities from a Reconciliation into a Reconciliation object. For now the only way I could find to load all the related entites to a single Recon is in multiple Lists. But I want to load every related entities in a Reconciliation object. If possible in an elegant way. Reconciliation recon = db.Reconciliations .Where(r => r.ReconNum == 382485).First(); List<ReconciliationDetail> reconDetails = recon.ReconciliationDetails.ToList(); List<JrnlEntryDetail> jrnlDetails = reconDetails.Select(r => r.JrnlEntryDetail).ToList(); List

Entity Framework 5 model first - Where is IDisposable gone?

筅森魡賤 提交于 2019-11-28 07:08:19
问题 In Entity Framework 5 model first, there seem to be some breaking changes due to the way the class files are generated (No more code generation, but T4 templates) 2 examples: The generated context file doesn't implement IDisposable anymore There isn't a constructor which takes a connectionstring anymore Are there more breaking changes? And what is the solution to them? 回答1: The default code generated from a model in Entity Framework 5 now inherits DbContext instead of ObjectContext. This

Data Annotations with Entity Framework 5.0 (database first)

萝らか妹 提交于 2019-11-28 06:51:31
What is the best way to use data annotations for validation if I'm using an Entity Framework (v5.0) database first approach? This is my partial class created by Entity Framework: //------------------------------------------------------------------------------ // <auto-generated> // This code was generated from a template. // // Manual changes to this file may cause unexpected behavior in your application. // Manual changes to this file will be overwritten if the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ using