entity-framework

GridView sorting and paging Entity Framework with calculated field

拜拜、爱过 提交于 2020-01-25 11:29:25
问题 I am paging and sorting a GridView which uses ObjectDataSource . The ObjectDataSource gets data from a List in my business layer, and this List is populated by an IEnumerable<Type> in my data layer which uses the Entity Framework. The guts of the paging and sorting is done in the data layer, as follows: var customers = (from c in entities.Customers select c).OrderBy(sortParameter).Skip(startRowIndex).Take(maximumRows)); As you can see, I am passing parameters from the ObjectDataSource to

Define Data Type of Computed Column

北慕城南 提交于 2020-01-25 11:09:14
问题 I have a computed column specified as follows: (case when [StartDate]<=getdate() AND [EndDate] IS NULL then (1) else (0) end) I'm trying to use the value of this column in Entity Framework. Is there any possible way to have this recognized as a boolean ? That, or can I have it defined as a bit in my database, based on its return values? As it is, Entity Framework considers it an int (as it seems to do whenever it's not clear). 回答1: Simply cast the value to bit , like this: CAST ((case when

Define Data Type of Computed Column

梦想与她 提交于 2020-01-25 11:08:44
问题 I have a computed column specified as follows: (case when [StartDate]<=getdate() AND [EndDate] IS NULL then (1) else (0) end) I'm trying to use the value of this column in Entity Framework. Is there any possible way to have this recognized as a boolean ? That, or can I have it defined as a bit in my database, based on its return values? As it is, Entity Framework considers it an int (as it seems to do whenever it's not clear). 回答1: Simply cast the value to bit , like this: CAST ((case when

Blazor GetAsync request returns 401 status code

ⅰ亾dé卋堺 提交于 2020-01-25 10:21:09
问题 I am new to blazor and trying to create an application using .NET Core /EF Core 3 and Visual studio 2019. I have setup a database model and an API for getting all addresses (/api/Address) and browsing to this in a browser returns all of the records in the database. But my My GetAsync method in the Razor file returns 401 which finally returns null. Here is my Razor code: @functions { Address[] addresses; protected override async Task OnInitializedAsync() { addresses = await Http.GetJsonAsync

Invoke constructor inside a linq query [duplicate]

眉间皱痕 提交于 2020-01-25 08:08:19
问题 This question already has answers here : Only parameterless constructors and initializers are supported in LINQ to Entities (13 answers) Closed 6 years ago . I need to invoke a constructor inside of a linq query. I am getting this error: Only parameterless constructors and initializers are supported in LINQ to Entities. Here's my linq query: IQueryable<Object> list = (from u in db.Object select new Object(u)); Here is my constructor: public Object(Object presentation){} 回答1: You have to use a

Invoke constructor inside a linq query [duplicate]

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-25 08:08:06
问题 This question already has answers here : Only parameterless constructors and initializers are supported in LINQ to Entities (13 answers) Closed 6 years ago . I need to invoke a constructor inside of a linq query. I am getting this error: Only parameterless constructors and initializers are supported in LINQ to Entities. Here's my linq query: IQueryable<Object> list = (from u in db.Object select new Object(u)); Here is my constructor: public Object(Object presentation){} 回答1: You have to use a

Get images from database in Entity Framework by passing id into ashx

余生颓废 提交于 2020-01-25 08:03:07
问题 In my homepage I Have a list of articles. When I click on any article it redirects to next page to view images of that article. in URL I am passing article id ( pr_id ) to next page. So to display resized images I am using handler. I need to display all the images which are associated to that pr_id . How do I get all the images which are stored in DB by passing id in Entity Framework. I need to get all the images which are associate to that pr_id . I don't know where I am kind of stuck. In my

How to handle an entity model with inheritance in a view?

扶醉桌前 提交于 2020-01-25 07:41:07
问题 Suppose I have an entity model consisting out of entity Car, and 2 entities (SportsCar, Truck) that inherit from Car. On my site I want to display a list of Cars, mixing SportsCars and Trucks, but also displaying the unique features of each. In my controller I retrieve all cars from my model and send them to the view. How can I build logic in my view that checks wether a car is a SportsCar or a Truck? 回答1: You could use display templates. Let's take an example. Model: public class Car {

Entity Framework 4 exception not being thrown / caught

左心房为你撑大大i 提交于 2020-01-25 06:32:35
问题 I am connecting to a MySQL database from Visual Studio 2010 using Net/Connector. This is the entity framework 4 linq query: int timeThreshold = 5; DateTime cutoffTime = DateTime.Now.AddMinutes(-timeThreshold); try { using (var context = new myEntities()) { var unprocessedMessages = from m in context.messages where m.createdDate < cutoffTime select m; } } catch (Exception e) { string exceptionString = e.InnerException.ToString(); } The Results view in the expanded unprocessedMessages displays

Entity Framework 4 exception not being thrown / caught

妖精的绣舞 提交于 2020-01-25 06:32:12
问题 I am connecting to a MySQL database from Visual Studio 2010 using Net/Connector. This is the entity framework 4 linq query: int timeThreshold = 5; DateTime cutoffTime = DateTime.Now.AddMinutes(-timeThreshold); try { using (var context = new myEntities()) { var unprocessedMessages = from m in context.messages where m.createdDate < cutoffTime select m; } } catch (Exception e) { string exceptionString = e.InnerException.ToString(); } The Results view in the expanded unprocessedMessages displays