entity-framework-4

Entity Framework Code First Lazy Loading

人走茶凉 提交于 2019-12-17 07:14:17
问题 I am having two object classes public class User { public Guid Id { get; set; } public string Name { get; set; } // Navigation public ICollection<Product> Products { get; set; } } public class Product { public Guid Id { get; set; } // Navigation public User User { get; set; } public Guid User_Id { get; set; } public string Name { get; set; } } When i load a user using dataContext, i get the list of Products being null (this is ok). If i add "virtual" keyword to Products list, public virtual

Exclude a field/property from the database with Entity Framework 4 & Code-First

北慕城南 提交于 2019-12-17 06:37:13
问题 I will like to know that is there a way to exclude some fields from the database? For eg: public class Employee { public int Id { get; set; } public string Name { get; set; } public string FatherName { get; set; } public bool IsMale { get; set; } public bool IsMarried { get; set; } public string AddressAs { get; set; } } How can I exclude the AddressAs field from the database? 回答1: In the current version the only way to exclude a property is to explicitly map all the other columns: builder

String.Equals() not working as intended

寵の児 提交于 2019-12-17 06:13:05
问题 I am using LINQ to search through one of my Entity Framework tables and find a "group" based on the name. The name is a string and appears to be Unicode (says it is in the edmx). I have a method GetGroup() and I pass in a name to search for. Debugging through the code, I already have a group named "Test" in my database. Once I pass in a group named "TEST" I expect it to return the "Test" which was already in the database. It for some reason, does not find the "Test" and thinks "TEST" doesn't

String.Equals() not working as intended

杀马特。学长 韩版系。学妹 提交于 2019-12-17 06:12:28
问题 I am using LINQ to search through one of my Entity Framework tables and find a "group" based on the name. The name is a string and appears to be Unicode (says it is in the edmx). I have a method GetGroup() and I pass in a name to search for. Debugging through the code, I already have a group named "Test" in my database. Once I pass in a group named "TEST" I expect it to return the "Test" which was already in the database. It for some reason, does not find the "Test" and thinks "TEST" doesn't

The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties

ぃ、小莉子 提交于 2019-12-17 05:38:22
问题 Using this code in Entity Framework I receive the following error. I need to get all the rows for a specific date, DateTimeStart is of type DataType in this format 2013-01-30 12:00:00.000 Code: var eventsCustom = eventCustomRepository.FindAllEventsCustomByUniqueStudentReference(userDevice.UniqueStudentReference) .Where(x => x.DateTimeStart.Date == currentDateTime.Date); Error: base {System.SystemException} = {"The specified type member 'Date' is not supported in LINQ to Entities. Only

A dependent property in a ReferentialConstraint is mapped to a store-generated column

佐手、 提交于 2019-12-17 04:58:28
问题 I get this error when writing to the database: A dependent property in a ReferentialConstraint is mapped to a store-generated column. Column: 'PaymentId'. public bool PayForItem(int terminalId, double paymentAmount, eNums.MasterCategoryEnum mastercategoryEnum, int CategoryId, int CategoryItemId) { using (var dbEntities = new DatabaseAccess.Schema.EntityModel()) { int pinnumber = 0; long pinid = 1; //getPinId(terminalId,ref pinnumber) ; var payment = new DatabaseAccess.Schema.Payment();

Creating dynamic queries with entity framework

落爺英雄遲暮 提交于 2019-12-17 04:20:18
问题 I would like to know what is the best way of creating dynamic queries with entity framework and linq. I want to create a service that has many parameters for sorting and filtering (over 50). I will be getting object from gui where these will be filled out... and query will be executed from a single service method. I looked around And I saw that I could dynamically create a string that can be executed at the end of my method. I don't like this way very much. Is there a better way to do this?

LEFT JOIN in LINQ to entities?

妖精的绣舞 提交于 2019-12-17 03:53:35
问题 I'm trying out LINQ to entities. I have a problem with the following: I want it to do this: SELECT T_Benutzer.BE_User ,T_Benutzer_Benutzergruppen.BEBG_BE FROM T_Benutzer LEFT JOIN T_Benutzer_Benutzergruppen ON T_Benutzer_Benutzergruppen.BEBG_BE = T_Benutzer.BE_ID the closest thing I've come to is this: var lol = ( from u in Repo.T_Benutzer //where u.BE_ID == 1 from o in Repo.T_Benutzer_Benutzergruppen.DefaultIfEmpty() // on u.BE_ID equals o.BEBG_BE where (u.BE_ID == o.BEBG_BE || o.BEBG_BE ==

Why does the Contains() operator degrade Entity Framework's performance so dramatically?

家住魔仙堡 提交于 2019-12-17 03:22:57
问题 UPDATE 3: According to this announcement, this has been addressed by the EF team in EF6 alpha 2. UPDATE 2: I've created a suggestion to fix this problem. To vote for it, go here. Consider a SQL database with one very simple table. CREATE TABLE Main (Id INT PRIMARY KEY) I populate the table with 10,000 records. WITH Numbers AS ( SELECT 1 AS Id UNION ALL SELECT Id + 1 AS Id FROM Numbers WHERE Id <= 10000 ) INSERT Main (Id) SELECT Id FROM Numbers OPTION (MAXRECURSION 0) I build an EF model for

ADO.Net EF - how to define foreign key relation in model first approach?

北城余情 提交于 2019-12-17 02:37:52
问题 I have been having previous issues regards to class inheritance and structuring a database around this and using the entity framework to no success. So I have tried to create the entities inside visual studio and see what database tables it creates automatically. I have a Entity MediaItem which is Abstract and Game Inherits from this. Game has a Console (Int) which corresponds to ConsoleID. However, when I generate the database I get an extra unwanted column (ConsoleTypes_ConsoleID) inside