Entity framework Explicit Loading multi-level - entity-framework

I tried load multi-level with explicit loading but an error occurred:
"The property path 'Channel.Posts' cannot be used for navigation properties. Property paths can only be used to access primitive or complex properties."
This is my code:
var listSubs;
using (var db = new GamePortalContext())
{
listSubs = db.Subscribers.Include("Channel").Where(o => o.User.Username == username.ToLower() && o.Channel.IsActive && o.Channel.IsPublic && o.Channel.Posts.Count(p => p.PublishTime <= DateTime.Now && p.IsActive && p.IsHot) > 0);
if (listSubs.Any())
{
listSubs = listSubs.OrderByDescending(o => o.Channel.ChannelTrack.LastPublishTime);
listSubs = (num == int.MinValue) ? listSubs : listSubs.Take(num);
foreach (var item in listSubs)
{
db.Entry(item).Collection(o => o.Channel.Posts).Query().Where(i => i.IsHot && i.IsActive && i.PublishTime <= DateTime.Now).Take(numpost).Load();
}
return listSubs.ToList();
}
else
{
return null;
}
}
Here is my post and channel entity
public partial class Post
{
public Post()
{
this.ReadPostLaters = new HashSet<ReadPostLater>();
}
public string PostId { get; set; }
public string Name { get; set; }
public string Alias { get; set; }
public string Description { get; set; }
public bool IsActive { get; set; }
public bool IsHot { get; set; }
public System.DateTime CreatedAt { get; set; }
public System.DateTime PublishTime { get; set; }
public int Views { get; set; }
public bool IsSticked { get; set; }
public int UpdatedTime { get; set; }
public bool IsSaved { get; set; }
public Nullable<int> ChannelId { get; set; }
public long UserId { get; set; }
public int PostType { get; set; }
public string UrlAvatar { get; set; }
public virtual Article Article { get; set; }
public virtual Channel Channel { get; set; }
public virtual Event Event { get; set; }
public virtual User User { get; set; }
public virtual ICollection<ReadPostLater> ReadPostLaters { get; set; }
public virtual Video Video { get; set; }
}
public partial class Channel
{
public Channel()
{
this.Ads = new HashSet<Ad>();
this.ChannelAdmins = new HashSet<ChannelAdmin>();
this.ChannelPlayers = new HashSet<ChannelPlayer>();
this.Notifications = new HashSet<Notification>();
this.Posts = new HashSet<Post>();
this.Subscribers = new HashSet<Subscriber>();
}
public int ChannelId { get; set; }
public string Name { get; set; }
public string Username { get; set; }
public int Voters { get; set; }
public int Subs { get; set; }
public float SiteScore { get; set; }
public float UserScore { get; set; }
public string HomeUrl { get; set; }
public string FanpageUrl { get; set; }
public string Publisher { get; set; }
public int Players { get; set; }
public Nullable<System.DateTime> PublishDate { get; set; }
public string Status { get; set; }
public bool IsActive { get; set; }
public bool IsHot { get; set; }
public bool IsPublic { get; set; }
public bool IsNew { get; set; }
public bool IsChanneling { get; set; }
public int CategoryId { get; set; }
public string UrlAvatar { get; set; }
public string UrlCover { get; set; }
public virtual ICollection<Ad> Ads { get; set; }
public virtual CategoryChannel CategoryChannel { get; set; }
public virtual ICollection<ChannelAdmin> ChannelAdmins { get; set; }
public virtual ICollection<ChannelPlayer> ChannelPlayers { get; set; }
public virtual ChannelTrack ChannelTrack { get; set; }
public virtual ICollection<Notification> Notifications { get; set; }
public virtual ICollection<Post> Posts { get; set; }
public virtual ICollection<Subscriber> Subscribers { get; set; }
}

change
db.Entry(item).Collection(o => o.Channel.Posts).Query().Where(i => i.IsHot && i.IsActive && i.PublishTime <= DateTime.Now).Take(numpost).Load();
to
db.Entry(item.Channel).Collection(o => o.Posts).Query().Where(i => i.IsHot && i.IsActive && i.PublishTime <= DateTime.Now).Take(numpost).Load();

Try changing this line:
listSubs = db.Subscribers.Include("Channel").Where(o => o.User.Username == username.ToLower() && o.Channel.IsActive && o.Channel.IsPublic && o.Channel.Posts.Count(p => p.PublishTime <= DateTime.Now && p.IsActive && p.IsHot) > 0);
To also call .Include("Channel.Posts"):
listSubs = db.Subscribers.Include("Channel").Include("Channel.Posts") .. etc;

Related

Can anyone give me a solution how we will merge the two different repositories i.e.. two tables in a same database we want to use a Linq query

Working code - but it is not getting output what is the wrong in this code:
var result = _favouriteProjectRepository.Entity()
.Where(x => x.UserId == userId)
.Select(x => new FavouriteProject
{
ProjectId = x.ProjectId,
}).ToList();
var resultset = await _projectrepository.Entity()
.Where(x => (filters.FiscalYear == null ||
filters.FiscalYear.Contains(Convert.ToInt32(x.ContractNo.ToString().Substring(0, 2)))) &&
(filters.IsFavourite == false &&
result.Contains(x.Id).ToString()))
.Select(x => new Tests
{
Id = x.Id,
Name = x.Name,
AdvertisementStatusId = x.AdvertisementStatusId,
CreatedOn = x.CreatedOn,
ContractNo = x.ContractN0,
})
.OrderBy(x => x.Name)
.ToListAsync();
Models:-
public class FavouriteProject
{
public int ProjectId { get; set; }
public string UserId { get; set; }
public virtual Project Project { get; set; }
}
public class Tests
{
public int Id { get; set; }
public string Name { get; set; }
public int? ContractNo { get; set; }
public int? AdvertisementStatusId { get; set; }
public DateTime? CreatedOn { get; set; }
public virtual ICollection<FavouriteCompany> FavouriteCompany { get; set; }
}
**filters**
public class ProjectFilters
{
public List<int> FiscalYear { get; set; }
public bool IsFavourite { get; set; }
}
**Project Model**
public class Project
{
public int Id { get; set; }
public string ProcurmentNo { get; set; }
public int? ContractNo { get; set; }
public int? ProjectSizeId { get; set; }
public int? SelectionProcedureId { get; set; }
public int? ResponseRequestedId { get; set; }
public int? AdvertisementStatusId { get; set; }
public int? NoOfPages { get; set; }
public string PreQualificationRequirements { get; set; }
public string Description { get; set; }
public string Name { get; set; }
public string MultilineDescription { get; set; }
public string BridgDesignWorkType { get; set; }
public string DbeMbeRequirements { get; set; }
public string SpecialNote { get; set; }
public decimal? BudgetAmount { get; set; }
public decimal? EstimatedContractAmount { get; set; }
public decimal? MaxumumContractAmount { get; set; }
public bool? IsMultipleContracts { get; set; }
public string ProposedScopeLoc { get; set; }
public string BondingRequirements { get; set; }
public string TechQuestionsAddressedTo { get; set; }
public int Status { get; set; }
public int? DistrictId { get; set; }
public DateTime? CreatedOn { get; set; }
public string ResponseEmail { get; set; }
public string ViewRFP { get; set; }
public string AdditionalInformation { get; set; }
public string LowBidDesign { get; set; }
public string AdminNote { get; set; }
public string MeetingLocationNotes { get; set; }
public string FdotKey { get; set; }
//public DateTime? EventDate { get; set; }
public bool IsUpdatesLocked { get; set; }
public bool? BdiProjectIndicator { get; set; }
public string LiabilityInsurance { get; set; }
public string ProjectThreshold { get; set; }
public int NumberOfContracts { get; set; }
public int? RelatedProjectCount { get; set; }
public string AdvertisementSpecialNotes { get; set; }
public string FMNSpecialNotes { get; set; }
public virtual ProjectSize ProjectSize { get; set; }
public virtual SelectionProcedure SelectionProcedure { get; set; }
public virtual ResponseRequested ResponseRequested { get; set; }
public virtual AdvertisementStatus AdvertisementStatus { get; set; }
public virtual District District { get; set; }
public virtual ICollection<ProjectEvent> ProjectEvents { get; set; }
public virtual ICollection<FinancialManagementNumber> FinancialManagementNumbers { get; set; }
public virtual ICollection<ProjectWorkGroup> ProjectWorkGroups { get; set; }
public virtual ICollection<ScrapedLink> ScrapedLinks { get; set; }
public virtual ICollection<ProjectStandardNote> ProjectStandardNotes { get; set; }
public virtual ICollection<FtpFileProject> FtpFileProjects { get; set; }
public virtual ICollection<CompanyProject> CompanyProjects { get; set; }
public virtual ICollection<ContactProject> ContactProjects { get; set; }
public virtual ICollection<ProjectUnderUtilizedWorkGroup> ProjectUnderUtilizedWorkGroups { get; set; }
public virtual ICollection<WorkProgram> WorkPrograms { get; set; }
[NotMapped]
public virtual ICollection<ScrapedProjectModel> ScrapedProjects { get; set; }
// public virtual FavouriteProject FavouriteProject { get; set; }
Can anyone give me simplified query to call both in single request?
And I have added my models and filters you can go through it I have used only one filters and the model of project because in that class only I have mentioned
Try the following query:
var query = _projectrepository.Entity().AsQueryable();
if (filters.FiscalYear?.Count > 0)
{
query = query.Where(x => filters.FiscalYear.Contains(Convert.ToInt32(x.ContractNo.ToString().Substring(0, 2))));
}
if (filters.IsFavourite)
{
var favouriteProjects = _favouriteProjectRepository.Entity()
.Where(x => x.UserId == userId);
query =
from p in query
join f in favouriteProjects on p.Id equals f.ProjectId
select p;
}
var resultset = await query
.Select(x => new Tests
{
Id = x.Id,
Name = x.Name,
AdvertisementStatusId = x.AdvertisementStatusId,
CreatedOn = x.CreatedOn,
ContractNo = x.ContractN0,
})
.OrderBy(x => x.Name)
.ToListAsync();

Entity-framework The column name is specified more than once in the SET clause or column list of an INSERT

I have entity
public class ImageTeam
{
public int Id { get; set; }
public int TeamID { get; set; }
public Team Team { get; set; }
public int PostTeamID { get; set; }
public string Image { get; set; }
public int ImageType { get; set; }
public int StatusPublic { get; set; }
public int StatusActive { get; set; }
public DateTime CreatedAt { get; set; }
}
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public int NoMember { get; set; }
public float Score { get; set; }
public int StatusActive { get; set; }
public int TeamType { get; set; }
public virtual List<TeamGroup> ListMember { get; set; }
public virtual List<ImageTeam> ListAvatar { get; set; }
public virtual List<ImageTeam> ListBanner { get; set; }
public DateTime CreatedAt { get; set; }
}
config data context
modelBuilder.Entity<Team>(entity =>
{
entity.HasMany(x => x.ListAvatar)
.WithOne(t => t.Team)
.HasForeignKey(pv => pv.TeamID);
});
when I post the data insert a new record entity ImageTeam then it show exception
I need to do...Help me
In the Team class you add another relation ListBanner to ImageTeam class ,you have not set an foreign key for it, so EF automatically creates a TeamID and because TeamId already in the class, it's throw exception . You also need to set an foreign key for second relation.
public class ImageTeam
{
public int Id { get; set; }
public int TeamID { get; set; }
public Team Team { get; set; }
public int BannerTeamId { get; set; }
public Team BannerTeam { get; set; }
public int PostTeamID { get; set; }
public string Image { get; set; }
public int ImageType { get; set; }
public int StatusPublic { get; set; }
public int StatusActive { get; set; }
public DateTime CreatedAt { get; set; }
}
entity.HasMany(x => x.ListAvatar)
.WithOne(t => t.Team)
.HasForeignKey(pv => pv.TeamID).OnDelete(DeleteBehavior.Restrict);
entity.HasMany(x => x.ListBanner)
.WithOne(t => t.BannerTeam)
.HasForeignKey(pv => pv.BannerTeamId).OnDelete(DeleteBehavior.Restrict);
I have found a solution:
edit Team entity:
public class Team
{
public int Id { get; set; }
public string Name { get; set; }
public int NoMember { get; set; }
public float Score { get; set; }
public int StatusActive { get; set; }
public int TeamType { get; set; }
public virtual List<TeamGroup> ListMember { get; set; }
public virtual List<ImageTeam> ListImage { get; set; }
public DateTime CreatedAt { get; set; }
}
*no config data context
create new model: TeamViewModel
public class TeamViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public int NoMember { get; set; }
public float Score { get; set; }
public int StatusActive { get; set; }
public int TeamType { get; set; }
public virtual List<TeamGroupViewModel> ListMember { get; set; }
public virtual List<ImageTeam> ListImage { get; set; }
public string AvatarUrl { get; set; }
public virtual List<ImageTeam> ListAvatar { get; set; }
public string BannerUrl { get; set; }
public virtual List<ImageTeam> ListBanner { get; set; }
public virtual List<ImageTeam> ListPost { get; set; }
}
in controller :
[Route("api/[controller]/{id}/view")]
[HttpGet("{id}")]
public IActionResult GetById(int id)
{
var team = _teamService.GetById(id);
var model = _mapper.Map<TeamViewModel>(team);
model = parserImageTeam(model);
return Ok(model);
}
[Route("api/[controller]/{UserId}/view-teams")]
[HttpGet("{UserId}")]
public IActionResult GetAllTeamOfUser(int UserId)
{
// list teams
var teams = _teamService.GetTeamOfUser(UserId);
var _teams = _mapper.Map<IList<TeamViewModel>>(teams);
var newTeams = new List<TeamViewModel>();
foreach (TeamViewModel team in _teams)
{
newTeams.Add(parserImageTeam(team));
}
return Ok(newTeams);
}
private TeamViewModel parserImageTeam(TeamViewModel teamModel)
{
var imageAvatars = new List<ImageTeam>();
var imageBanners = new List<ImageTeam>();
var imagePosts = new List<ImageTeam>();
bool avt = false, banner = false;
foreach (ImageTeam image in teamModel.ListImage)
{
if (image.ImageType == Constants.ImageType.IMAGE_AVATAR_TEAM)
{
image.Image = parserUrlImage(image);
imageAvatars.Add(image);
if (!avt)
{
teamModel.AvatarUrl = image.Image;
avt = true;
}
}
if (image.ImageType == Constants.ImageType.IMAGE_BANNER_TEAM)
{
image.Image = parserUrlImage(image);
imageBanners.Add(image);
if (!banner)
{
teamModel.BannerUrl = image.Image;
banner = true;
}
}
if (image.ImageType == Constants.ImageType.IMAGE_POST_TEAM)
{
image.Image = parserUrlImage(image);
imagePosts.Add(image);
banner = true;
}
}
teamModel.ListAvatar = imageAvatars;
teamModel.ListBanner = imageBanners;
teamModel.ListPost = imagePosts;
return teamModel;
}
private string parserUrlImage(ImageTeam model)
{
string url = Configuration.GetValue<string>("BaseVariables:BaseUrl");
// another controller handle request (ImagesController)
return model.Image = url + "/Images/" + Constants.ImageType.getFolderName(model.ImageType).ToLower() + "/" + model.TeamID + "?ImageType=" + model.ImageType + "&imageName=" + model.Image;
}

Entity framework navigation property is null

I have two models using Entity Framework.
public class Player
{
public int PlayerId { get; set; }
public string Name { get; set; }
public string Sex { get; set; }
public string Plays { get; set; }
public string FavouriteSurface { get; set; }
}
public class SinglesMatch
{
public int SinglesMatchId { get; set; }
public int Player1Id { get; set; }
public int Player2Id { get; set; }
public int PlayerIdWinner { get; set; }
public DateTime Date { get; set; }
public string Venue { get; set; }
public string Score { get; set; }
public List<Player> Players { get; set; }
}
I am using the below code to attempt to display the Name of the player, based on the PlayerId in the SinglesMatch model matching the PlayerID from the Player model.
#foreach (var item in #Model)
{
<ul id="Players" class="bg-success"></ul>
<br/>
<h3>Date - #Html.DisplayFor(#modelItem => item.Date)</h3>
<li>Venue - #Html.DisplayFor(#modelItem => item.Venue)</li>
<li>Player 1 - #Html.DisplayFor(#modelItem => item.Players.First(p => p.PlayerId == item.Player1Id).Name)</li>
<li>Player 2 - #Html.DisplayFor(#modelItem => item.Players.First(p => p.PlayerId == item.Player2Id).Name)</li>
<li>Score- #Html.DisplayFor(#modelItem => item.Score)</li>
}
Upon debugging, the navigation property is always showing as null when the model is retrieved from my repository.
Am I using the navigation property in the correct fashion ? is there a problem with my query ?
Edit to include DbContext:
public TennisTrackerContext() : base("name=TennisTrackerContext")
{
}
public DbSet<Player> Players { get; set; }
public DbSet<PlayerRecord> PlayerRecords { get; set; }
public DbSet<SinglesMatch> SinglesMatches { get; set; }
public DbSet<DoublesMatch> DoublesMatches { get; set; }
public DbSet<Venue> Venues { get; set; }
}
}
You need to add a bridge table. Sql will create this automatically but you won't have access to the variables unless you create it in c#.
public class Player
{
public int PlayerId { get; set; }
public string Name { get; set; }
public string Sex { get; set; }
public string Plays { get; set; }
public string FavouriteSurface { get; set; }
List<PlayerInMatch> Matches { get; set; }
public Player()
{
Matches = new List<PlayerInMatch>();
}
}
public class PlayerInMatch
{
public int Id { get; set; }
public int PlayerId { get; set; }
[ForeignKey("PlayerId")]
public Player Player { get; set; }
public int SinglesMatchId { get; set; }
[ForeignKey("SinglesMatchId")]
public SinglesMatch SinglesMatch { get; set; }
}
public class SinglesMatch
{
public int SinglesMatchId { get; set; }
public int PlayerIdWinner { get; set; }
public DateTime Date { get; set; }
public string Venue { get; set; }
public string Score { get; set; }
public List<PlayerInMatch> Players { get; set; }
public SinglesMatch()
{
Players = new List<PlayerInMatch>();
}
}
static void Main(string[] args)
{
var match = new SinglesMatch();
match.Players.Select(c => c.Player.Name);
}
You need to make your navigation property virtual to enable lazy/eager loading:
public class SinglesMatch
{
public int SinglesMatchId { get; set; }
public int Player1Id { get; set; }
public int Player2Id { get; set; }
public int PlayerIdWinner { get; set; }
public DateTime Date { get; set; }
public string Venue { get; set; }
public string Score { get; set; }
public virtual List<Player> Players { get; set; }
}
Also, did you define the relationship between SinglesMatch and Singles in fluent api?
EDIT: I see you don't have any relations mapped through annotations or fluent api whatsoever, I suggest you take a look at this:
https://msdn.microsoft.com/en-us/data/jj591617.aspx

Automapper maps source to destination but dest values are always null

I'm new to automapper and I'm having a problem with it. In this case the automapper is used to map models(EntityFramework generated) to my own viewmodels. This is what happens, the sourcemodel with it's values is mapped to a destinationmodel but the dest values are always null. What's going on with the values?
Now what did I do:
I referenced the automapper to my project and bootstrapped the mappings.
public static void RegisterAutoMapperMappings()
{
Mapper.Initialize(x =>
{
// Add the mappingprofiles you configured below
x.AddProfile(new RegistrationViewModelProfile());
});
}
public static IMappingExpression<TSource, TDest> IgnoreAllUnmapped<TSource, TDest>(this IMappingExpression<TSource, TDest> expression)
{
expression.ForAllMembers(opt => opt.Ignore());
return expression;
}
public class RegistrationViewModelProfile : Profile
{
protected override void Configure()
{
CreateMap<RegistrationViewModel, contact>().IgnoreAllUnmapped();
CreateMap<contact, RegistrationViewModel>().IgnoreAllUnmapped();
CreateMap<RegistrationViewModel, emailaddress>().IgnoreAllUnmapped();
CreateMap<emailaddress, RegistrationViewModel>().IgnoreAllUnmapped();
CreateMap<RegistrationViewModel, password>().IgnoreAllUnmapped();
CreateMap<password, RegistrationViewModel>().IgnoreAllUnmapped();
//Always check if mapping is valid
Mapper.AssertConfigurationIsValid();
}
}
My viewmodel:
public class RegistrationViewModel
{
public HttpPostedFileBase file { get; set; }
public String EmailAddress { get; set; }
public String Password { get; set; }
public string contact_givenname { get; set; }
public string contact_surname_prefix { get; set; }
public string contact_surname { get; set; }
public string contact_gender { get; set; }
public string contact_country { get; set; }
public string contact_residence { get; set; }
public Nullable<DateTime> contact_birth_date{ get; set; }
public DateTime create_date { get; set; }
public ICollection<int> Contact_roles { get; set; }
public string Emailaddress_verificationkey { get; set; }
}
My model:
public partial class contact
{
public contact()
{
this.contact_connection_rel = new HashSet<contact_connection_rel>();
this.contact_emailaddress_password_rel = new HashSet<contact_emailaddress_password_rel>();
this.contact_emailaddress_rel = new HashSet<contact_emailaddress_rel>();
this.contact_service_role_rel = new HashSet<contact_service_role_rel>();
this.given_answer = new HashSet<given_answer>();
this.given_answer1 = new HashSet<given_answer>();
}
public int contact_id { get; set; }
public string contact_initials { get; set; }
public string contact_givenname { get; set; }
public string contact_surname_prefix { get; set; }
public string contact_surname { get; set; }
public string contact_nickname { get; set; }
public string contact_gender { get; set; }
public Nullable<System.DateTime> contact_birth_date { get; set; }
public string contact_country { get; set; }
public string contact_residence { get; set; }
public string contact_ssn { get; set; }
public Nullable<System.DateTime> create_date { get; set; }
public Nullable<System.DateTime> modify_date { get; set; }
public Nullable<System.DateTime> delete_date { get; set; }
public virtual ICollection<contact_connection_rel> contact_connection_rel { get; set; }
public virtual ICollection<contact_emailaddress_password_rel> contact_emailaddress_password_rel { get; set; }
public virtual ICollection<contact_emailaddress_rel> contact_emailaddress_rel { get; set; }
public virtual ICollection<contact_service_role_rel> contact_service_role_rel { get; set; }
public virtual ICollection<given_answer> given_answer { get; set; }
public virtual ICollection<given_answer> given_answer1 { get; set; }
}
And to test the configuration the following lines are used. The vars contain the destination objects but are always null:
contact c = new contact();
contact testC = unitOfWork.ContactRepository.Find(82);
var x = Mapper.Map<contact, RegistrationViewModel>(testC);
var y = Mapper.Map(regModel, c, typeof(RegistrationViewModel), typeof(contact));
var b = Mapper.DynamicMap<RegistrationViewModel, contact>(regModel);
var z = Mapper.Map<RegistrationViewModel, contact>(regModel, c);
var w = Mapper.Map<RegistrationViewModel, contact>(regModel);
expression.ForAllMembers(opt => opt.Ignore());
You're telling AutoMapper to ignore all properties, so nothing gets mapped.
If you just want to ignore non-matching properties, see this answer for one way, otherwise you're going to have to explicitly map each property between the objects.

EF code first property not mapped

The problem I'm encountering is when I try to insert a new record in a ASPxGridView which is a master of detail in an asp.net page.
This only occurs when adding a new record is required when there is no record.
EnderecoEscola entity:
namespace DAL
{
[Table("CAD_ENDERECO_ESCOLA")]
public class EnderecoEscola
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ENDESC_ID { get; set; }
[Required]
public int ESCOLA_ID { get; set; }
[Association("Escolas", "ESCOLA_ID", "ESCOLA_ID")]
[ForeignKey("ESCOLA_ID")]
public virtual Escola Escola { get; set; }
[Required]
public int TPOEND_ID { get; set; }
[ForeignKey("TPOEND_ID")]
public virtual TipoEndereco TipoEndereco { get; set; }
[Required]
public int ENDESC_UF_ID { get; set; }
[ForeignKey("ENDESC_UF_ID")]
public virtual UnidadeFederativa UnidadeFederativa { get; set; }
[Required]
public int ENDESC_MUN_iD { get; set; }
[ForeignKey("ENDESC_MUN_iD")]
public virtual Municipio Municipio { get; set; }
[StringLength(10), Required]
[MinLength(8)]
public string ENDESC_CEP { get; set; }
[StringLength(100), Required]
[MinLength(10)]
public string ENDESC_ENDERECO { get; set; }
[StringLength(15)]
public string ENDESC_NRO { get; set; }
[StringLength(25)]
public string ENDESC_COMPL { get; set; }
[StringLength(70)]
public string ENDESC_BAIRRO { get; set; }
[NotMapped]
public String TPEND_DESCRICAO { get; set; }
[NotMapped]
public String UF_SIGLA { get; set; }
[NotMapped]
public String MUN_DESCRICAO { get; set; }
}
}
DAL :
namespace DAL.utilities
{
public class OperationCadEnderecoEscola
{
public IQueryable<EnderecoEscola> GetId(int idEsc)
{
using (SecurityCtx ctx = new SecurityCtx())
{
ctx.Configuration.LazyLoadingEnabled = false;
var query = ctx.EnderecoEscola.Include("TipoEndereco").Include("UnidadeFederativa").Include("Municipio").Where(w => w.ESCOLA_ID == idEsc).OrderBy(p => p.ENDESC_ENDERECO).ToList().
Select(w => new EnderecoEscola
{
ENDESC_ID = w.ENDESC_ID,
ESCOLA_ID = w.ESCOLA_ID,
TPOEND_ID = w.TPOEND_ID,
ENDESC_UF_ID = w.ENDESC_UF_ID,
ENDESC_MUN_iD = w.ENDESC_MUN_iD,
ENDESC_CEP = w.ENDESC_CEP,
ENDESC_ENDERECO = w.ENDESC_ENDERECO,
ENDESC_NRO = w.ENDESC_NRO,
ENDESC_COMPL = w.ENDESC_COMPL,
ENDESC_BAIRRO = w.ENDESC_BAIRRO,
TPEND_DESCRICAO = w.TipoEndereco.TPEND_DESCRICAO != null ? w.TipoEndereco.TPEND_DESCRICAO : w.TPEND_DESCRICAO,
UF_SIGLA = w.UnidadeFederativa.UF_SIGLA != null ? w.UnidadeFederativa.UF_SIGLA : w.UF_SIGLA,
MUN_DESCRICAO = w.Municipio.MUN_DESCRICAO != null ? w.Municipio.MUN_DESCRICAO : w.MUN_DESCRICAO
}).Distinct().AsQueryable();
return query;
}
}
}
}
When applying for inclusion in ASPxGridView a new record and the method in DAL public IQueryable <EnderecoEscola> getId (int idEsc) is invoked to retrieve the data and they do not exists it is adding a new record on the master and detail occurs error
A field or property with name 'TPEND_DESCRICAO' was not found in the
selected data source.
Someone could guide me on how to solve the problem.
Tks.