entity-framework-4

Navigation Properties on Join Tables in Entity Framework

别说谁变了你拦得住时间么 提交于 2019-12-13 02:29:42
问题 So I have a table in my SQL database: CompanyRelationships -------------------- ID CompanyID RelatedCompanyID PermissionGroupID Which defines when a company allows access to it's records to another company. The "CompanyID" is the company that is granting access, the "RelatedCompanyID" is the company that is getting the access. Yes, two records could exist for the same two companies (each granting access to the other) The problem is when I generate the entity model from the db (In Visual

How to deal with inherited entity in EF and MVC app?

本秂侑毒 提交于 2019-12-13 01:17:05
问题 I am developing MVC application and using razor syntax. I have used model first method. I have two entities, Customer and Lead. Lead is inherited from Customer. When IsActive property is true then Customer treated as a Lead, otherwise it will be a customer. Please check edmx file image. When I genrated DB from model , I get the two tables Customer Table and Customer_Lead table. This is Customer table. and This is Customer_Lead Table. Now the problem is when I run index view of lead entity ,

ASP.NET C# EF - How to benefit the full object after selecting it?

家住魔仙堡 提交于 2019-12-13 00:57:33
问题 I've been working on ASP.NET C# with Entity Framework and some people help me very much on certain key points. There also one point I could not understand fully. Aren't we supposed to use the object and its subobjects (foreign key relation table data) when we retrieve the data from EF? Here is my database design (which was also displayed in my previously answered question) In my code, I simply get Member entity like this: //In some aspx.cs file var Mem = new MemberManager().GetById(2); //In

Linq to Entities - Subquery in the where statement

倖福魔咒の 提交于 2019-12-13 00:45:44
问题 This must be simple, but I've been searching for 2 hours, and can't find an answer. How do I write this in Linq to Entities: SELECT Reg4, Reg5, Reg6 FROM dbo.Table1 WHERE Reg1 = 15 AND Reg2 = ( SELECT MAX(Reg2) FROM dbo.Table2 WHERE Reg1 = 15); Is it possible to do it both in query expressions and method based syntaxes? Tks 回答1: var r1 = 15; var q = from t in Context.Table1 where t.Reg1 == r1 && t.Reg2 == Context.Table2 .Where(t2 => t2.Reg1 == r1) .Max(t2 => t2.Reg2) select t; Easier still if

How can I dynamically customize a POCO proxy in EF 4?

╄→гoц情女王★ 提交于 2019-12-13 00:28:33
问题 I would like to dynamically customize some POCO classes overriding myself the virtual members to be able to compile LINQ to Entities queries. I know about the ObjectMaterialized event but that happens after the class instantiation. I would like to be able to create the proxy myself, override the virtual members I want and then pass along to the EF, is that possible? Imagine the following POCO class: public class Consumer { /* That´s a virtual property with an association in EF */ public

pre-compiled view not affecting performance

筅森魡賤 提交于 2019-12-13 00:27:52
问题 EDIT : This question is not about compiled queries, it is about generating the EF database view at compile time. From the ADO.NET team blog: Exploring the Performance of the ADO.NET Entity Framework - Part 1: View Generation 56%– A big part of creating an abstracted view of the database is providing the actual view for queries and updates in the store’s native language. During this step, the store views are created. The good news is there is a way of making view generation part of the build

Fluent API, EF 4.1: a problem of inheritance and foreign key

百般思念 提交于 2019-12-13 00:14:13
问题 There are several simple classes: The first class: public class User { public int UserId { get; set; } public string Username { get; set; } // ... public ICollection<Topic> Topics { get; set; } } The second class: public class Publication { public int PublicationId { get; set; } public string Title { get; set; } / ... public User Author { get; set; } } The third class: public class Topic: Publication { public string TopicContent { get; set; } // ... } After creating a database for my model I

Modify SSDL runtime for ADO.NET and Entity Framework

大憨熊 提交于 2019-12-13 00:13:32
问题 I would like to undertand how to modify on fly the SSDL in a connection string. I have followed the tutorial here: http://www.codeproject.com/Articles/82017/Preparing-an-Entity-Framework-model-for-multi-prov , but I am still not able to understand how to configure the "res://" line and where to put the .ssdl file. I have a complex hierarchical structure to be compiance to an adapter structure: <project root> / Toolkit / Database / External / Adapter / Abstract.cs / File / File.ssdl / Adapter

How can I change Discriminator (__Disc__) field while it is used as a condition

断了今生、忘了曾经 提交于 2019-12-12 22:54:26
问题 I have to update and change Discriminator( _ Disc _ ) field of a table while mapped entities doesn't have it as an entity member . any solution? 回答1: Discriminator column is used to define type of entity in TPH inheritance and EF cannot change it - never. It is like inheritance in any object oriented language - once you define object of some type you cannot make it different type - you can only cast it to parent but it will still be instance of original type. The only way to change it to

How can I improve my business layer objects mapping into a database? Is it time for a O/R mapper?

社会主义新天地 提交于 2019-12-12 22:31:03
问题 As I began writing web applications with asp.net I started with small projects that used a Linq-To-SQL mapper for database access to a MSSQL Server. After gaining some expierence I switched into a classic 3 tier with Graphic Layer, Business Layer, Data Layer. The only function of the Data Layer was to provide methods insert/update/delete without any logic and logic the form of selection methods. Over the time I realized that it would be better not to provide the database classes up to the GUI