Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving issues passing Objects among tiers
    primarykey
    data
    text
    <p>I'm trying to do something that should be real simple but I'm getting errors I don't know how to correct. Also, I don't even know if I'm doing things the "correct" way.</p> <p>I have 3 entities. My first entity is called Bill and it's my main one. The other two are Repeat and Type. Bill has foreign keys (i.e. TypeId) which point to their respective primary keys. Both Type and Repeat are similar. They have their Id and description.</p> <p>What I'm trying to do with EF and LINQ to Entity: Get all bills with all the properties of Bill but instead of the TypeId, I want TypeDesc.</p> <p>This is an N tier Solution with 3 projects Thus far I have my data layer I call Model, business layer I call BLL and my presentation later I call GUI.</p> <pre><code>namespace BillApp.Model { public class BillModel { public List&lt;BillType&gt; GetAllBills() { using (BillsEntities be = new BillsEntities()) { var results = from o in be.Bills .Include("Type") .Include("Repeat") select new { BillId = o.BillId, Name = o.Name, URL = o.URL, PaymentAmount = o.PaymentAmount, Balance = o.Balance, DueDate = o.DueDate, TypeDesc = o.Type.TypeDesc, RepeatDesc = o.Repeat.RepeatDesc, Username = o.UserName }; return results.ToList(); } } } public class BillType { #region Properties public int BillId { get; set; } public string Name { get; set; } public string URL { get; set; } public decimal PaymentAmount { get; set; } public decimal Balance { get; set; } public DateTime DueDate { get; set; } public string TypeDesc { get; set; } public string RepeatDesc { get; set; } public string Username { get; set; } #endregion } } </code></pre> <p>results returns an error Cannot implicitly convert type <code>System.Linq.IQueryable&lt;AnonymousType#1&gt;</code> to <code>System.Collections.Generic.List&lt;BillApp.Model.BillType&gt;</code></p> <p>Next I try and pass the object to my BLL with this code.</p> <pre><code>namespace BillApp.BLL { public class BillBLL { public List&lt;BillType&gt; GetAllBills() { BillModel b = new BillModel(); return b.GetAllBills(); } } } </code></pre> <p>But BillType has an error:The type or namespace name 'BillType' could not be found (are you missing a using directive or an assembly reference?)</p> <p>What am I missing? What can I do better?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload