entity-framework

Defining an Entity Framework 1:1 association

旧街凉风 提交于 2020-01-22 09:25:10
问题 I'm trying to define a 1:1 association between two entities (one maps to a table and the other to a view - using DefinedQuery) in an Entity Framework model. When trying to define the mapping for this in the designer, it makes me choose the (1) table or view to map the association to. What am I supposed to choose? I can choose either of the two tables but then I am forced to choose a column from that table (or view) for each end of the relationship. I would expect to be able to choose a column

Possible to set column ordering in Entity Framework

≡放荡痞女 提交于 2020-01-22 08:18:36
问题 Is there any possible configuration to set database column ordering in entity framework code first approach..? All of my entity set should have some common fields for keeping recordinfo public DateTime CreatedAt { get; set; } public int CreatedBy { get; set; } public DateTime ModifiedAt { get; set; } public int ModifiedBy { get; set; } public bool IsDeleted { get; set; } I want to keep this fields at the end of the table. Is there any possible EF configuration that i can use to config this

Entity Framework duplicate object and all child properties

巧了我就是萌 提交于 2020-01-22 05:34:35
问题 Example structure public class Page { public int PageId { get; set; } public string Prop1 { get; set; } public string Prop2 { get; set; } public virtual List<Section> Sections { get; set; } } public class Section { public int SectionId { get; set; } public int PageId { get; set; } public virtual Page Page { get; set; } public virtual List<Heading> Headings { get; set; } } public class Heading { public int HeadingId { get; set; } public int SectionId { get; set; } public virtual Section

Entity Framework duplicate object and all child properties

拜拜、爱过 提交于 2020-01-22 05:34:09
问题 Example structure public class Page { public int PageId { get; set; } public string Prop1 { get; set; } public string Prop2 { get; set; } public virtual List<Section> Sections { get; set; } } public class Section { public int SectionId { get; set; } public int PageId { get; set; } public virtual Page Page { get; set; } public virtual List<Heading> Headings { get; set; } } public class Heading { public int HeadingId { get; set; } public int SectionId { get; set; } public virtual Section

Is there a suggested pattern for using LINQ between the Model & DataAccess Layers in a DDD based Layered Architecture

会有一股神秘感。 提交于 2020-01-22 05:32:25
问题 I've been reading Tim McCarthy's awesome book on DDD in .NET. In his example application though, his underlying data access is using SqlCE and he's handcrafting the SQL inline. I've been playing with some patterns for leveraging Entity Framework but I've gotten stuck on how exactly to map the IRepository linq queries to the underlying data access layer. I have a concrete repository implementation called. public EFCustomerRepository : IRepository<DomainEntities.Customer> { IEnumerable

Entity Framework : Filter nested collection by value of its properties

。_饼干妹妹 提交于 2020-01-22 03:24:05
问题 I have model as below class MyClass() { public int Id { get; set; } public List<Item> Items { get; set; } } class Item { public int Id { get; set; } public string Name { get; set; } } both are added to DBContext as DbSets , now I would like to filter out the MyClass using the value of the Name property in the Items collection. How do I do this? 回答1: First of all correct your POCOs this way: public class MyClass { public int Id { get; set; } public virtual ICollection<Item> Items { get; set; }

getting duplicate rows for each row using linq query

≯℡__Kan透↙ 提交于 2020-01-22 03:18:45
问题 I have db schema having tables like this below, i am trying to get the results using left join or normal join on these table using the below query. Somehow getting duplicate rows like as mentioned below. Requests (table) RequestStage (table) ------------- ---------------- id RequestStageid createdAt(datetime) name (values: RequestSubmitted,Inreview) RequestTypeId MasterSectionID RequestStatusID RequestStageID id (FK)(localCodes) MasterSections (table) ------------------------- MasterSectionId

how to add item in db in asp.net mvc? [duplicate]

最后都变了- 提交于 2020-01-22 03:06:27
问题 This question already exists : how to add item to form in controller in asp.net mvc? [closed] Closed last month . all item from "view" send to "ActionResult Create" so we want to quantify "matchid" and "userid" from the server side but srver side's validation errors and it dosen't let the program add data in database. also if we comment "(ModelState.IsValid)" the program will run corectly but we need this. what shoud we do? public ActionResult Create([Bind(Include = "id,creatdate,bugname

DataTable iteration gives unwanted data

折月煮酒 提交于 2020-01-22 02:31:13
问题 I am iterating through a DataTable using SqlDataAdapter and storing it in a list. Here is my code. public IEnumerable<DataRow> GetRecord() { var table = new DataTable(); using (var da = new SqlDataAdapter("SELECT * FROM mv_tbl", "ConnectionString")) { da.Fill(table); List<DataRow> list = new List<DataRow>(); foreach (DataRow r in table.Rows) { list.Add(r); } return list; } } This gives me a result which has unnecessary data also. Here is the result. [{"RowError":"", "RowState":2, "Table":[{

EF. How to include only some sub results in a model?

若如初见. 提交于 2020-01-21 21:03:38
问题 I'm trying to select list of Users and for each User JobTitle in correct language depended of strLang selected by user. Something like that: IList<User> myData; myData = Context.Users.Where(u => u.Location == strLocation) .Include(u => u.JobTitles.Where(e => e.Language == strLang)) .ToList(); But it seems Include doesn't like Where clause 回答1: You can't conditionally include only a few entities of a related collection, so you should use projection to get the stuff you need: IList<User> myData