Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:58:22+00:00 2026-05-29T20:58:22+00:00

By injecting values ​​into my domain object, I would keep the values ​​of some

  • 0

By injecting values ​​into my domain object, I would keep the values ​​of some properties.

Example:

Domain model

public class Person
{
    public string Name { get; set; }
    public Guid ID { get; set; }
    public DateTime CreateAt { get; set; }
    public string Notes { get; set; }
    public IList<string> Tags { get; set; }
}

View Model

public class PersonViewMode
{
    public string Name { get; set; }
    public Guid ID { get; set; }
    public DateTime CreateAt { get; set; }
    public string Notes { get; set; }
    public IList<string> Tags { get; set; }

    public PersonViewMode() { ID = Guid.NewGuid(); } //You should use this value when it is the Target
}

Sample

var p = new Person
            {
                ID = Guid.NewGuid() //Should be ignored!
                ,
                Name = "Riderman"
                ,
                CreateAt = DateTime.Now
                ,
                Notes = "teste de nota"
                ,
                Tags = new[] {"Tag1", "Tag2", "Tag3"}
            };

var pvm = new PersonViewMode();

pvm.InjectFrom(p); //Should use the ID value generated in the class constructor PersonViewMode
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:58:23+00:00Added an answer on May 29, 2026 at 8:58 pm

    if you delete the set; from from the ViewModel’s ID then it won’t be set;

    otherwise you could save the value of ID in a separate variable and put it back after injecting,

    or you can create a custom valueinjection that would ignore “ID” or would receive a list of properties to ignore as a parameter


    here’s the example for a custom injection that receives a list of property names to ignore:

    public class MyInj : ConventionInjection
    {
        private readonly string[] ignores = new string[] { };
    
        public MyInj(params string[] ignores)
        {
            this.ignores = ignores;
        }
    
        protected override bool Match(ConventionInfo c)
        {
            if (ignores.Contains(c.SourceProp.Name)) return false;
            return c.SourceProp.Name == c.TargetProp.Name && c.SourceProp.Type == c.TargetProp.Type;
        }
    }
    

    and use it like this:

    pvm.InjectFrom(new MyInj("ID"), p);
    

    if you need to ignore more, you can do like this:

    pvm.InjectFrom(new MyInj("ID","Prop2","Prop3"), p); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to prevent Castle Windsor from automatically injecting dependencies into properties
I have a problem in php code inserting values into database (I use PHPMyAdmin).
First i gave all values of row in JTAble. While inserting table values into
When inserting a row in mysql database, string values need to be enclosed in
I have a issue with my Spring.Net configuration where its not injecting an object.
I am having trouble inserting values into my Account table that's in a SQL
i am inserting values into a table if the record exists already replace it,
Hello I'm trying to save string into SQLite database, but nothing happens. I have
I have this form which can insert/update values into database table. <div id=settingsdiv style=width:350px;
I'm try to insert values into my sqlite table using a python script. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.