entity-framework

How to use Json data type in C# Entity Framework model?

北城余情 提交于 2021-01-23 01:48:54
问题 model.cs [Column(TypeName = "json")] public string application_role { get; set; } Its MySQL, data type of particular column is json , and how to add it in a model class. I tried with DataAnnotations but getting error as The specified type member 'application_role' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Linq Query to get data context.sc_employee_details .Where(e => e.user_name.Equals(userName)) .Select(o => o

How to use Json data type in C# Entity Framework model?

时光怂恿深爱的人放手 提交于 2021-01-23 01:46:53
问题 model.cs [Column(TypeName = "json")] public string application_role { get; set; } Its MySQL, data type of particular column is json , and how to add it in a model class. I tried with DataAnnotations but getting error as The specified type member 'application_role' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. Linq Query to get data context.sc_employee_details .Where(e => e.user_name.Equals(userName)) .Select(o => o

Why does my EF appear to return duplicate rows from my SQL View which is working?

╄→гoц情女王★ 提交于 2021-01-22 21:53:55
问题 I've looked the question up but nothing I have found is working for me. I created a view in SQL which works when you run it in the Management Studio. When the view is accessed from my MVC Application, EF is returning identical rows instead of rows with different data. Table: Cars [Id] [Registration] [Make] [Model] Table: Bookings [Id] [BookingStartDate] [BookingEndDate] [CarId] View: CarBookings SELECT [C].[Id], [C].[Registration], [C].[Make], [C].[Model], [B].[BookingStartDate], [B].

Owned type property not persisting for a modified entity in EF Core

喜夏-厌秋 提交于 2021-01-22 10:28:37
问题 I'm trying to achieve something in EF Core that worked very well for me in EF 6. I'm serializing the contents of a List<T> property as a Json string in the DB. <T> can be pretty much anything, since Json.Net takes care of serializing whatever we throw at it. My collection exposes a Json string property and takes care of serializing/deserializing itself. This approach is convenient and efficient for structured nested data where a relational model would bring needless overhead and complexity.

Owned type property not persisting for a modified entity in EF Core

你说的曾经没有我的故事 提交于 2021-01-22 10:28:34
问题 I'm trying to achieve something in EF Core that worked very well for me in EF 6. I'm serializing the contents of a List<T> property as a Json string in the DB. <T> can be pretty much anything, since Json.Net takes care of serializing whatever we throw at it. My collection exposes a Json string property and takes care of serializing/deserializing itself. This approach is convenient and efficient for structured nested data where a relational model would bring needless overhead and complexity.

What exactly does IQueryable mean?

余生颓废 提交于 2021-01-22 08:28:18
问题 I'm not sure I understand what exactly IQueryable is. I understand that it doesn't get me all the entities and puts the constraint part in memory but executes it as part of the command it sends to the database. Please correct me if I'm mistaken and tell me, why should my repository functions return IQueryable and not a simple List ? 回答1: An IQueryable is not actually a collection of entities, rather it describes how to obtain that collection. The data is never retrieved from the source until

Index out of range exception in FieldNameLookup.GetOrdinal when running SqlQuery EF

ε祈祈猫儿з 提交于 2021-01-21 08:52:50
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. Kirsten Greed wants to reward an existing answer : Reward this answer and draw attention to stackoverflow.com/questions/65753462/… We are getting eventually an IndexOutOfRange exception when running code like this: result.Data = dbOptima.Database.ExecuteStoredProcedure( task, StoredProcedureValues.PROC_GET_TASKS).ToList(); ,where ExecuteStoredProcedure does the following: public static

Index out of range exception in FieldNameLookup.GetOrdinal when running SqlQuery EF

纵饮孤独 提交于 2021-01-21 08:51:06
问题 The bounty expires in 3 days . Answers to this question are eligible for a +50 reputation bounty. Kirsten Greed wants to reward an existing answer : Reward this answer and draw attention to stackoverflow.com/questions/65753462/… We are getting eventually an IndexOutOfRange exception when running code like this: result.Data = dbOptima.Database.ExecuteStoredProcedure( task, StoredProcedureValues.PROC_GET_TASKS).ToList(); ,where ExecuteStoredProcedure does the following: public static

Unique string for each record in the database table

自作多情 提交于 2021-01-21 04:33:05
问题 In my Asp.Net MVC 5 project I use Entity Framework code first to work with MS SQL database. Suppose this is the table: public class Ticket { [Key] public int Id { get; set; } [Required] public string ReferenceCode { get; set; } //Rest of the table } In this table, whenever I add a new code I want the ReferenceCode column to be a unique and random AlphaNumeric (containing only letters and digits) string with a specific length. This will allow users to refer to a specific ticket for instance.

Unable to create an object of type '[DBContext's Name]'. For the different patterns supported at design time [closed]

孤人 提交于 2021-01-21 00:34:09
问题 Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 months ago . Improve this question I'm following one of Mosh Hamedani Course on ASP.NET MVC in Udemy. I came across one error while designing my Database using code-first (Entity Framework). At first, I got the error of " No DbContext was found in assembly" . After resolving this problem