entity-framework-6

Creating a list of entities that supports IBindingListView?

别来无恙 提交于 2019-12-12 02:58:20
问题 I use the following code in my data repository to return a list of entities. I want to bind to the list using a winforms bindingsource, and then to be able to support and filter the bindingsource I currently use something like mybindingSource.datasource = repository.GetList(p => p.Id > 0 && p.Archived == false, x => x.Organisation); however mybindingSource.SupportsFilter returns false. The repository function is public virtual IList<T> GetList(Func<T, bool> where, params Expression<Func<T,

After Submit TotalPages Throws error

大兔子大兔子 提交于 2019-12-12 02:44:21
问题 I have a little problem with my paging ("double TotalPage = @ViewBag.TotalPages; on Partial View"), after submiting on Create or Edit the paging throws the following error: "Cannot convert null to 'double' because it is a non-nullable value type". I have created a partial view that contains the list (Crud Operations using Ajax), all works fine, I can go to different pages in the list but when I submit a new row or edit an existing one it displays that error. Here is the code for it: public

The relationship could not be changed because one or more of the foreign-key properties is non-nullable

自作多情 提交于 2019-12-12 02:39:38
问题 Exception : System.InvalidOperationException: The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted. I have seen some solutions for the

Setting the context's connection name depending on the user that logs in

流过昼夜 提交于 2019-12-12 02:27:18
问题 This used to be a Web Forms application and I'm rewriting it in MVC. The connection name is stored in the user's details and depending on the user, I need to pass a different connection name. In WebForms this was solved by setting a Session variable in Global.asax and then every time the context is needed, I'd create the context in a using statement, passing the Session variable in the context constructor like this: using (IAccountContext db = new MainContext(Session["cn"]) { } In MVC I'm

Would it be best to call context.SaveChanges only once?

吃可爱长大的小学妹 提交于 2019-12-12 02:16:49
问题 I'm semi new to EF and I'm converting a Windows Service App over to using EF. It will read a text file with 11k employees in it and look to see if a record exists or not and either do an insert or update. Currently I'm looping through each line, create a new entity object with the values, pass that to a data class and in there it will look up the entity to see if it will insert or update. Thing is I'm calling the context.SaveChanges() each record. Now I'm wondering if I should create a list

how to include stored procedures with Entity Framework Reverse POCO Generator version 2.14.3

只谈情不闲聊 提交于 2019-12-12 02:14:45
问题 I am using the Entity Framework Reverse POCO Generator version 2.14.3 and I would like to include only stored procedures with name starts "usp_CMT_update*" in Apps schema. I used default settings for stored proocedure in the .tt file but only some of them were generated. I also tried regex pattern but still didn't get the stored proc generated. Please help. Thanks. // Stored Procedures ***************************************************** // Use the following regex filters to include or

Why is Entity Framework so slow with join statements?

人盡茶涼 提交于 2019-12-12 02:09:52
问题 I have an EF 6 query that has about 6 linq join statements in it. When I step through my code with the debugger, I can see that the query statement takes roughly 6 seconds to run. With a SQL trace, I can tell that the actual query, which looks like I would expect it to, takes 0 ms and returns 0 rows. I removed the join statements 1 by one. With each join statement removed, the EF statement took 1 second less to execute. The select portion of the query never changed, only the number of joins.

EF Fluent API for hierarchical data

廉价感情. 提交于 2019-12-12 02:09:41
问题 I want to store hierarchical data in the database and need help how to configure the model. There is also a set of hierarchical data per user. After the data has been stored in the database, it is changed very rarely. The database, I plan to use are as follows: User Id int TreeEntity Id int UserId int ParentId int TreeEntity.UserId reference to User.Id TreeEntity.ParentId reference to TreeEntity.Id . If ParentId is unset, it is the root in the tree. I've thought about trying to configure EF

How can I make Linq extension method available for the entities?

守給你的承諾、 提交于 2019-12-12 01:56:21
问题 I wrote a method that extends System.Linq class. My ContainsAnyWord method allows me to search all words in a string against a string instead of comparing one string to another. Here is the method that I wrote to extend Linq public static class LinqExtension { public static bool ContainsAnyWord(this string value, string searchFor) { if (!string.IsNullOrWhiteSpace(value) && !string.IsNullOrWhiteSpace(searchFor)) { value = value.ToLower(); IEnumerable<string> tags = StopwordTool.GetPossibleTags

Selecting Left Table on Inner Join to DbScanExpression in Entity Framework Interceptor

家住魔仙堡 提交于 2019-12-12 01:53:39
问题 Further to the SO question answered here, i'm trying to select all of the columns in the right table only without having to explicitly specify the column names together with UserId from the left table. Any ideas on how this can be done? public override DbExpression Visit(DbScanExpression expression) { var table = expression.Target.ElementType as EntityType; if (table != null && table.Name == "User") { return expression.InnerJoin( DbExpressionBuilder.Scan(expression.Target.EntityContainer